• Post Reply Bookmark Topic Watch Topic
  • New Topic

is my variable thread safe?  RSS feed

 
Geetha Ratnam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I suspect if my implementation shown below is proper and thread safe.

This is the scenario:
I have web service with a service exposed "MyServices" with an exposed method "getService()" -- The first code.
And also we have our SOAP mappings and the calls to busibness logic reside in "run()" method of MyServicesHandler which is a thread.

from the getService() of MyServices, a reference to myServiceOutputParams1 is passed to the constructor of MyServicesHandler and modified in the run() method of MyServicesHandler.

is class variable myServiceOutputParams of MyServicesHandler is thread safe?

This is very critical and urgent. Appreciate your response please.


----------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------------------------------------------------------------
-Geetha



[HENRY: Added Code Tags]
 
Henry Wong
author
Sheriff
Posts: 22852
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// The class variable myServiceOutputParams2 is updated.


The answer, of course, is ... it depends. It depends on what is changed. It depends on what is affected by the change. It depends on what the other threads that are using the same object are doing, and how are they affected... etc.

Henry
 
Geetha Ratnam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getService() of class MyServices is running on the main thread which is created for a web request. And myServiceOutputParams1 is getting initialised here to enable the access of it in here. There is no other update to the object other than the reference creation.

run() method of MyServicesHandler is the place where this object is getting populated.

Considering this fact, would it be possible for us to confirm if it is thread safe or not?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geetha Ratnam wrote:is class variable myServiceOutputParams of MyServicesHandler is thread safe?


There isn't any such variable in the code you posted.
 
Geetha Ratnam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry.. It shoud be myServiceOutputParams2.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geetha Ratnam wrote:sorry.. It shoud be myServiceOutputParams2.


Okay. Then I don't see where you synchronize access to that variable. And since it has package-private access, any class in the same package can access the variable directly, and it isn't possible to synchronize that access. So I would have to say it isn't thread-safe.

Exactly what was so critical and urgent about that? I've noticed that people who say things are urgent tend to make more errors in their posts, which results in back-and-forth clarifications which wouldn't have been necessary if they had just taken a deep breath and spent ten seconds more writing a good post.
 
Geetha Ratnam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the responses.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!