Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Job progress monitoring, and results in separate thread (outside the Job)
Job progress monitoring, and results in separate thread (outside the Job) [message #466756] Tue, 24 April 2007 11:12 Go to next message
Eclipse UserFriend
Hi all,

Got a tricky little problem here using the Job framework and reporting progress. I have an operation that could take some time, however the work for this job is not performed by the RCP application itself - it is performed by a process on a server and the progress is reported back to the RCP application.

I currently have code that looks a bit like this:

Job job = new Job("Publishing") {
protected IStatus run(IProgressMonitor monitor) {
progressMonitor = monitor;

setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
setProperty(IProgressConstants.ACTION_PROPERTY, getPublishingCompletedAction());

monitor.beginTask("Publishing", 100);

monitor.worked(1);
monitor.subTask("Initialising...");

setUploading(true);
processMessage(1, "Beginning Publishing process...", 0, 5);

System.out.println("PUBLISHING: Marker 1");

new Thread() {
public void run() {
try {
System.out.println("PUBLISHING: Marker 2");

// Code to start the publish on the server

System.out.println("PUBLISHING: Marker 3");
} catch (Exception e) {
e.printStackTrace();
}
}

{
start(); // static initialiser
}
};

System.out.println("PUBLISHING: Marker 4");

// Code to create a listener in a new thread to monitor progress

System.out.println("PUBLISHING: Marker 5");

return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();

However, when the user clicks the button to start this action and create this job, the publishing process in our server application is started, but the job seems to end before any progress has come back, and therefore the Job progress dialog never gets updated.

I can see that the 'return Status.OK_STATUS' is being called and this seems to be ending the job. I am updating 'progressMonitor' from the listener thread but, of course, the progress monitor isn't around by the time any progress comes back that triggers the listener.

Is there a way to set this job running indefinitely (i.e. not calling 'return Status.OK_STATUS' to end the job) until the server process returns the final message that the publish has finished (at which point I can then end the Job).

Any help would be greatly appreciated. Thanks all!
Re: Job progress monitoring, and results in separate thread (outside the Job) [message #467184 is a reply to message #466756] Mon, 30 April 2007 09:31 Go to previous messageGo to next message
Eclipse UserFriend
...its funny how some threads in this forum get loads of hits and replies, and some none at all. I would have thought this was quite a common problem that developers must have come across. Obviously not!

In case someone in the future does happen to come across this and is in a similar situation, I ended up solving this is a rather hacky, but ultimately pragmatic way.

In the Job:

Job job = new Job("Publishing") { 
	protected IStatus run(IProgressMonitor monitor) { 
		progressMonitor = monitor; 

		setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); 
		setProperty(IProgressConstants.ACTION_PROPERTY, getPublishingCompletedAction()); 

		monitor.beginTask("Publishing", 100); 

		monitor.worked(1); 
		monitor.subTask("Initialising..."); 

		processMessage(1, "Beginning Publishing process...", 0, 5); 

		System.out.println("PUBLISHING: Marker 1"); 

		new Thread() { 
			public void run() { 
				try { 
					System.out.println("PUBLISHING: Marker 2"); 

					// Code to start the publish on the server 

					System.out.println("PUBLISHING: Marker 3"); 
				} catch (Exception e) { 
					e.printStackTrace(); 
				} 
			} 
			{ 
				start(); // static initialiser 
			} 
		}; 

		System.out.println("PUBLISHING: Marker 4"); 

		// Code to create a listener in a new thread to monitor progress 

		// Set the publishing flag to true. This flag will be set to false elsewhere by the thread handling incoming messages.
		isPublishing = true;

		while (isUploading) {
			try {
				Thread.sleep(2000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		System.out.println("PUBLISHING: Marker 5"); 

		return Status.OK_STATUS; 
	} 
}; 
job.setUser(true); 
job.schedule(); 
Re: Job progress monitoring, and results in separate thread (outside the Job) [message #467188 is a reply to message #467184] Mon, 30 April 2007 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi Craig,

Also, you might use WorkspaceJob and JobChangeAdapter.

Charlie


Craig Pugsley wrote:
> ..its funny how some threads in this forum get loads of hits and replies, and some none at all. I would have thought this was quite a common problem that developers must have come across. Obviously not!
>
> In case someone in the future does happen to come across this and is in a similar situation, I ended up solving this is a rather hacky, but ultimately pragmatic way.
>
> In the Job:
>
>
> Job job = new Job("Publishing") { 
> 	protected IStatus run(IProgressMonitor monitor) { 
> 		progressMonitor = monitor; 
> 
> 		setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); 
> 		setProperty(IProgressConstants.ACTION_PROPERTY, getPublishingCompletedAction()); 
> 
> 		monitor.beginTask("Publishing", 100); 
> 
> 		monitor.worked(1); 
> 		monitor.subTask("Initialising..."); 
> 
> 		processMessage(1, "Beginning Publishing process...", 0, 5); 
> 
> 		System.out.println("PUBLISHING: Marker 1"); 
> 
> 		new Thread() { 
> 			public void run() { 
> 				try { 
> 					System.out.println("PUBLISHING: Marker 2"); 
> 
> 					// Code to start the publish on the server 
> 
> 					System.out.println("PUBLISHING: Marker 3"); 
> 				} catch (Exception e) { 
> 					e.printStackTrace(); 
> 				} 
> 			} 
> 			{ 
> 				start(); // static initialiser 
> 			} 
> 		}; 
> 
> 		System.out.println("PUBLISHING: Marker 4"); 
> 
> 		// Code to create a listener in a new thread to monitor progress 
> 
> 		// Set the publishing flag to true. This flag will be set to false elsewhere by the thread handling incoming messages.
> 		isPublishing = true;
> 
> 		while (isUploading) {
> 			try {
> 				Thread.sleep(2000);
> 			} catch (Exception e) {
> 				e.printStackTrace();
> 			}
> 		}
> 
> 		System.out.println("PUBLISHING: Marker 5"); 
> 
> 		return Status.OK_STATUS; 
> 	} 
> }; 
> job.setUser(true); 
> job.schedule(); 
> 
Re: Job progress monitoring, and results in separate thread (outside the Job) [message #467201 is a reply to message #466756] Mon, 30 April 2007 15:54 Go to previous message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Tue, 24 Apr 2007 11:12:36 -0400, Craig Pugsley wrote:

> Hi all,
>
> Got a tricky little problem here using the Job framework and reporting progress. I have an operation that could take some time, however the work for this job is not performed by the RCP application itself - it is performed by a process on a server and the progress is reported back to the RCP application.
>
> I currently have code that looks a bit like this:
>
....
>
> However, when the user clicks the button to start this action and create this job, the publishing process in our server application is started, but the job seems to end before any progress has come back, and therefore the Job progress dialog never gets updated.
>
> I can see that the 'return Status.OK_STATUS' is being called and this seems to be ending the job. I am updating 'progressMonitor' from the listener thread but, of course, the progress monitor isn't around by the time any progress comes back that triggers the listener.
>
> Is there a way to set this job running indefinitely (i.e. not calling 'return Status.OK_STATUS' to end the job) until the server process returns the final message that the publish has finished (at which point I can then end the Job).
>
> Any help would be greatly appreciated. Thanks all!

>

Why are you starting the publishing inside that Thread? Thats what the
Job is for. Its redundant and that is why its masking the progress.
Previous Topic:More Hibernate issues
Next Topic:Eclipse RCP Patch 1 & 2
Goto Forum:
  


Current Time: Sat May 17 18:43:08 EDT 2025

Powered by FUDForum. Page generated in 0.04018 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top