• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two Thread Problem  RSS feed

 
Purujit Saha
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two thread Tread & Tmain
Tread is an infinite loop reads a configuration file after after certain period.
Tmain works based on the information Tread collected from configuration file.
If Tmain executes before Tread fully read the conf. file then it will through null pointer Exception.

Now how to make it sure that only after reading the file fully Tmain is executed...

thnx in advance...
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have some flag in the TThread which indicates whether the conf file has been read.
 
Lakshmanan Arunachalam
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My understanding from your post is,

1. Read/Write should not be simultaneous.
2. For every write there should be one read operation

if the requirements are the same as above, similar problem is explained in java.sun.com

URL : http://java.sun.com/docs/books/tutorial/essential/threads/synchronization.html

Hope this helps !

Lakshmanan
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 5 look at Semaphore, Exchanger, CountdownLatch and so on. All of these help you coordinate the actions of two or more threads.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a variable indicating when info is available, along with wait/notify.
 
Roy Chow
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, You could use the "join" method in the Tmain thread just before exit. This might help.

in the Tmain method
{
Tread.jon();
}
 
dana rao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
was that the real roy chow wing hung???
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!