• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading with static methods

 
Nolan Evans
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a multithreading capabilities in my program, then I invoke a static method that writes timestamp to a file. What will happen? will all threads use this same static method? or will the program crash?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all threads will access the same method, so you should synchronize it. But even if not, the program shouldn't crash, but the contents of the file will be unpredictable.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross posting is a no no.
http://forum.java.sun.com/thread.jspa?threadID=679394&tstart=30
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would hesitate to call posting on two completely different websites "cross-posting".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!