Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [pde-dev] Blocking jobs

Hi Leen,

I'm kind of perplexed regarding your approach. I do not see how you can correctly synchronize your thread and your main application using the jobs to call the thread. A thread must run a function and synchronize himself over a communication link to receive run-time inputs. You cannot call a public function of that class to transmit input. It should look something like this:

Thread t = new Thread();
t.run();

for (int i; ...; i++)
	New Job();
	t.enqueue(job);

Thread:

Public void run()
{
	while(!messagequeue.empty())
	{
		Job job = dequeue();
		job.execute();
	}
}

This way you will be sure that each job is executed sequentially.

J.P. Shields

-----Message d'origine-----
De : pde-dev-bounces@xxxxxxxxxxx [mailto:pde-dev-bounces@xxxxxxxxxxx] De la part de Leen Toelen
Envoyé : 2 décembre 2005 13:48
À : Eclipse PDE general developers list.
Objet : Re: [pde-dev] Blocking jobs

Hi,

thanks for your reply. What I do now is something like this:

Thread t = new Thread();
t.run();

for(int i;...;i++)
       New Job()
       job.setThread(t)
       job.schedule()

Now they all appear running at the same time (they are not waiting for
one another), but I guess the run sequentially in the one Thread,
basically solving my problem. The only rreason they have to run
sequentially is because the workload will get too high if I launch 100
jobs at the same time.

Could I use a lock somehow too?

Regards,
Leen



On 12/2/05, Jean-Philippe Shields <jean-philippe.shields@xxxxxxxxx> wrote:
> If I understand correctly, your thread is the worker and your application is sending it multiple jobs. In that case your application and your thread will execute concurrently, so each job will begin as soon as your thread receives it and could finish even before your application sends another job to the thread worker. This may be the reason that you're seeing that they all appear at the same time but if there is only one thread, all the jobs will be executed sequentially by the thread.
>
> -----Message d'origine-----
> De: pde-dev-bounces@xxxxxxxxxxx [mailto:pde-dev-bounces@xxxxxxxxxxx] De la part de Leen Toelen
> Envoyé: 2 décembre 2005 11:37
> À: Eclipse PDE general developers list.
> Objet: Re: [pde-dev] Blocking jobs
>
> What happens if I create one Thread and set this for all jobs with
> setThread(theOne). They all appear to be running at the same time.
>
> Regards,
> Leen Toelen
>
> On 12/2/05, Jean-Philippe Shields <jean-philippe.shields@xxxxxxxxx> wrote:
> > You need to implement this pseudo-code:
> >
> > The basic thing to do is to implement a list in your worker class, fifo or priority depends on you. You put your jobs in that list and then your worker runs on the list getting the first job until the list is empty. I don't think that there is an easy way to do that with Java or Eclipse because it is not a concurrent or parallel framework.
> >
> > If you intend to use threads, you will also need to implement multithreading security and persistence data on your jobs, which will be very difficult.
> >
> >         1 - Enqueue jobs in a list (FIFO)
> >                 workers.enqueue(job)
> >
> >                 public void enqueue(JOB job)
> >                 {
> >                         jobList.add(job);
> >                 }
> >
> >         In Your workers:
> >
> >         1 - while (!jobList.empty())
> >                 {
> >                         job = dequeuehead()
> >                         //Execute job
> >                         job.execute();
> >                 }
> >
> >                 Private Job dequeuehead()
> >                 {
> >                         Job temp;
> >                         temp = jobList.removefirst;
> >                         Return temp;
> >                 }
> >
> > I don't know any framework in java suitable for that, but in C++ you would like to use something called ACE: http://www.cs.wustl.edu/~schmidt/ACE.html.
> > I Hope it helps a bit.
> >
> > J.P. Shields
> >
> > -----Message d'origine-----
> > De: pde-dev-bounces@xxxxxxxxxxx [mailto:pde-dev-bounces@xxxxxxxxxxx] De la part de Leen Toelen
> > Envoyé: 2 décembre 2005 10:15
> > À: Eclipse PDE general developers list.
> > Objet: [pde-dev] Blocking jobs
> >
> > Hi,
> >
> > I am submitting multiple jobs at once, all of the same Class. I would
> > like that only one of these jobs can run at the time, so all jobs of
> > the same kind wait until the running job is finished, then take the
> > second one etc. Is there an easy way to do so?
> >
> > Regards,
> > Leen Toelen
> > _______________________________________________
> > pde-dev mailing list
> > pde-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/pde-dev
> >
> > _______________________________________________
> > pde-dev mailing list
> > pde-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/pde-dev
> >
> _______________________________________________
> pde-dev mailing list
> pde-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/pde-dev
>
> _______________________________________________
> pde-dev mailing list
> pde-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/pde-dev
>
_______________________________________________
pde-dev mailing list
pde-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/pde-dev



Back to the top