Results 1 to 7 of 7
- 07-18-2007, 02:53 AM #1
Member
- Join Date
- Mar 2007
- Posts
- 16
- Rep Power
- 0
- 07-18-2007, 02:55 AM #2
Senior Member
- Join Date
- Mar 2007
- Posts
- 134
- Rep Power
- 0
Local variables are threadsafe--each thread gets its own copy of locals.
The objects that the variables point to may not be threadsafe--for instance, if some other thread has references to the same objects.
- 07-18-2007, 12:49 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 4
- Rep Power
- 0
You needn't worry about multithreaded access to local variables, method parameters, and return values, because these variables reside on the Java stack. In the JVM, each thread is awarded its own Java stack. No thread can see or use any local variables, return values, or parameters belonging to another thread.
but you need only be concerned with instance and class variables when you worry about thread safety. Because all threads share the same heap, and the heap is where all instance variables are stored, multiple threads can attempt to use the same object's instance variables concurrently.
- 08-09-2007, 06:59 PM #4
Senior Member
- Join Date
- Mar 2007
- Posts
- 134
- Rep Power
- 0
thanks Ashish
- 12-21-2010, 01:20 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Hi All
I want to know whether in the following case my code is thread safe or not
I am having one Parent class in that class i am having global varible of another class Say B.
In the method from Parent class I am calling method on the object B.
above method is taking the arraylist as parameter to the method.
this Arraylist is modifying in the Parent Class Method and I am Iterating over the Arraylist in the B class method which is parameter to the method.
In above case arraylist is threadSafe ?
Thanks in advance
- 12-21-2010, 01:28 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
One more thing i have forgotten
Both classes are singleton only
-
rato, please do not hijack old threads with a new question. Rather, please ask your question in its own thread and if desired link to this thread. I'm locking this thread. Please private message me if you have any questions.
Similar Threads
-
The safe way to stop a thread
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:31 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM -
Struts framework. Is this thread safe?
By JavaAl2 in forum Web FrameworksReplies: 1Last Post: 01-17-2008, 03:01 AM -
Local Variables for a static method - thread safe?
By mikeg1z in forum Advanced JavaReplies: 1Last Post: 11-16-2007, 01:06 AM -
is synchronization on method passing local variables as parameters needed
By reddzer in forum Java ServletReplies: 0Last Post: 11-10-2007, 04:47 PM


LinkBack URL
About LinkBacks

Bookmarks