Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Job not guaranteed to be scheduled ? eg @startup
Job not guaranteed to be scheduled ? eg @startup [message #628127] Thu, 23 September 2010 09:20 Go to next message
Guy Rooms is currently offline Guy RoomsFriend
Messages: 8
Registered: May 2010
Junior Member
Are there any known conditions in which a Job is not scheduled at all ?

Situation:
I have a job who's doing some queries, the job is created/scheduled upon certain event.
I have the impression that - sometimes - the newly created job is not scheduled at all.
This only seems to occur when the initiating event is triggered upon eclipse startup.

Code excerpt
[0] Job job = new MyJob();
[1] job.schedule();
[2] int state = job.getState();
[3] if (Job.NONE == state) {
[4] // never should get here, right ?
[5] }

Isn't it true we never should get at line [4] ? Or are there known exceptions ? Startup eg ?

Env:
Version: 3.5.0
Build id: I20090611-1540
java.vm.info=mixed mode
java.vm.name=Java HotSpot(TM) Server VM
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=14.0-b16

Thx in advance,

Guy.
Re: Job not guaranteed to be scheduled ? eg @startup [message #628832 is a reply to message #628127] Fri, 24 September 2010 11:05 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 23.09.2010 11:20, Guy Rooms wrote:
> Are there any known conditions in which a Job is not scheduled at all ?
>
> Situation:
> I have a job who's doing some queries, the job is created/scheduled upon
> certain event.
> I have the impression that - sometimes - the newly created job is not
> scheduled at all.
> This only seems to occur when the initiating event is triggered upon
> eclipse startup.
>
> Code excerpt
> [0] Job job = new MyJob();
> [1] job.schedule();
> [2] int state = job.getState();
> [3] if (Job.NONE == state) {
> [4] // never should get here, right ?
> [5] }
>
> Isn't it true we never should get at line [4] ? Or are there known
> exceptions ? Startup eg ?

This is a misconception: There is no guarantee at all
that after schedule has been started, the job-state has
a specific value. Don't use the state property of jobs
for this kind of things. Actually I would never try to
interpret it and trying to construct a logic around this.
Note that the spec explicitly warns here:

"Note that job state is inherently volatile, and in most cases clients
cannot rely on the result of this method being valid by the time the
result is obtained."

What are you trying to achieve? If you want to get informed,
whether your job is ready, you should register as a job listener.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Job not guaranteed to be scheduled ? eg @startup [message #629151 is a reply to message #628832] Mon, 27 September 2010 11:20 Go to previous message
Guy Rooms is currently offline Guy RoomsFriend
Messages: 8
Registered: May 2010
Junior Member
Daniel,

Thx for your clarification.
I had a closer look into spec, and indeed, as you mentioned, jobstate is not something to rely on.
What I wanted to do is in fact create a job, schedule it and wait for its completion before proceeding: the Job's run method is querying/building up some critical data, clients should only access it after the query job has completed.

So, I hoped to achieve this by

[0] Job job = new MyJob();
[1] job.schedule();
[2] job.join();

but noticed job.join even returned before the job actually started.
That's why I started playing with the getState method (ref the inital code excerpt)
Now, reading the spec again, also the join does not guarantee to return only after job has actually run.

So, what's the best thing to do then ?
- register listener +
- block (sleep) code path untill I get informed about RUNNING + NONE state sequence ?

I also tried this yet ended up in waiting for a job that never got scheduled / started.
I guess that blocking the one (..) calling thread(s) did had the side effect the job never got scheduled. Is that possible ?

Maybe I should leave Job as a solution for my particular problem and consider something else: I'm currently using a plain Runnable which seems to do "the job", yet, it would be nicer to show some progress. That's what a typical eclipse user would expect..

Any suggestion is still most welcome.
Previous Topic:view reference not garbage collected after dispose
Next Topic:P2 - "Install New Software" behind company proxy
Goto Forum:
  


Current Time: Fri Dec 19 22:46:58 GMT 2014

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

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