• 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

Synchronization Issue (Is Runnable the culprit)

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers,

I always thought when it comes to Threads: implementing Runnable is flexible and advantageous over Extending Thread. However I'm encountering a peculiar problem. Could you please suggest alternatives, get-arounds or solutions:

Here's the scenario:

I have a Dialog where in user asks for some Tasks(each implemented by a sepearte Thread)

Now here's what i do:

1> Close the dialog (SwingUtilities.invokeLater (Runnable(closeDialog));

2> In a loop : do the tasks sequentially using 2 threads: 1 actually does the work; 2nd checks for status of the task; I add both of them to a Hashtable

3> Use a Monitor implementing Runnbale... check the Hashtable; get The threads; join() each of them; at the end refreah the screen

When Monitor is extended as a thread then I'm able to achieve the synchronization; but when Monitor is implemented as a thread then screen is unresponsive until tasks are completed.

What am I missing when Monitor is implemented from Runnable? WIll making Monitor extend from a thread have other impacts?

Please let me know

Ravi
 
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
do not use synchronized methods, use only synchronized blocks of code. Start there.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic