• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Process sequence

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, hope you can give me a few ideas where to look to solve this problem:

I have a component that recieves a message.
I have an executor with a method execute() that is called by part of a framework. The execute method waits until the component recieves a message and notifies listeners (eg the executor).

I'm trying to then get the component to wait until the Executor has finished with the message.

Ive tried to use a second wait/notify but i get a race condition, being notified before waiting etc.

Currently im using a rather rubbishy spinlock checking if the executor has finished every 10ms.

I can make changes to the component and the executor but i cant access other parts of the framework im working in .

I assume i need some kind of lock so that each section of code is executed in the sequence described. Do you think some kind of control sequence object would assist?

help!

Tom
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you clarify what you need? As far as the Executor's thread is concerned, is it finished with the message before it notifies the Component?

If it is, it sounds like you need to synchronize the notification. If the Executor notifies before finishing with the message, maybe it shouldn't.
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well ideally i would like the component to notify the executor to the arrival of a message and then wait for the executor to notify after it has finished executing the message. But sometimes the executor will notify before the component has started waiting because the component's thread has been paused by the jvm.

Cheers.

Tom
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm missing why the executor has to be on another thread at all if we're just going to wait for it. If your main thread starts a new thread or can get ahold of the other thread object it can join():

But we might as well do all the work in the main thread. This has a little threading advantage going on:

This is tougher if your runnable is in a thread pool, cause the threads never really end. Maybe ...

You'll have to imagine the runner locking and unlocking the lock.

Is that close to what you need?
[ August 25, 2005: Message edited by: Stan James ]
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tom Hill:
...Ive tried to use a second wait/notify but i get a race condition, being notified before waiting etc...



Thats called a bug. You should fix it before you abandon the strategy. And what do you mean by second? whats the first doing?
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like i havent explained very well. This was my attempted structure:



the problem is that the 2nd notify is called before the 2nd wait has started.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait and notify are use to tell you to _check_ if conditions are correct to proceed. They should not be used to tell you to proceed in and of themselves.

Component Thread:


Executor Thread
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see!
I was using seperate lock objects to notify and wait but I was using the boolean messageAvaliable/messsageProcessed parameters. I shall give it a go straight away.

Thanks very very very much!

Tom
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic