• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization Issue (Is Runnable the culprit)  RSS feed

 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do not use synchronized methods, use only synchronized blocks of code. Start there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!