• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Threads Calling Static Methods  RSS feed

 
ratnadeep rakshit
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi geeks,
i just m workin on a project for Messenger development.
My problem is --
1)Whether calling the same Static method from multiple
Threads result in loss of data or deadlock???
I want to call a method called ---- Server.processMessage(String msg) which is static method of server class.Will my message be lost with multiple threds.
2)If yes - then wats the solution?
plz help...i need it in job tomorrow
thanx
samabhik
2)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch... I think.
I'm not sure I'm too thrilled with the sound of your display name; given that it doesn't match your signature, I suspect it's not a real name at all. You might want to have a look at our naming policy and then make some adjustments here.
Now, regarding your problem: the answer is "it depends." A class has to be designed properly to be used in a multithreaded environment. The answers to your questions depend on how the class was meant to be used. After you've fixed your display name, you might want to post some more details in a reply to this thread.
 
ratnadeep rakshit
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well...mr.Hill, m new to javaranch...
still,i dint get wat u meant however...
apart from my signature thing, wat is most important for me is the solution of the above problem...so if u can,kindly provide help...
my question is ---
Can I call a Static method --- Server.processMessage(String msg) [it processes the client messages for per socket] from multiple Threads.Will I lose any data? or result in deadlock?
kindly help
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As to your question, I thought I answered it pretty clearly: if the method was designed to be used in a multithreaded environment, then it will work fine. If it wasn't, then there is certainly a possibility that you'll get data loss. If it was designed for multithreaded use, but badly so, then you may see deadlocks. As I said, it depends.
[ April 20, 2004: Message edited by: Ernest Friedman-Hill ]
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one of the first thing I would try is to synchronize the method.
 
Roshan Lal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
I'm not sure I'm too thrilled with the sound of your display name; given that it doesn't match your signature, I suspect it's not a real name at all...

Ernest,
This looks a very real name to me! Apart from Captalizing the first letters, there is absolutely nothing wrong with this name.
Hope that helps
Roshan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!