Local « Development « Java Thread Q&A

Home
Java Thread Q&A
1.concurrency
2.Development
3.Exception
4.Notify
5.Operation
6.Socket
7.State
8.synchronize
9.Thread Safe
10.ThreadPool
Java Thread Q&A » Development » Local 

1. Local Variable    coderanch.com

Hi, Is it possible for a Thread to access a local variable created by other Thread? For example, Thread x access a method and create a local variable. Thread x has not finished, but then Thread y access the same method and also create a local variable. Is it possible for Thread y to access the local variable created by Thread ...

2. Thread sharing local variables?    coderanch.com

A method is defined in a class that implements Thread. If a method has local variables, and is called twice, will the 2 invocations share the copies of the local variables? or will the local variables have their own values for each invocation of the method. (I have an understanding that they will have their own local space) When then will ...

3. Threads and a local variable    coderanch.com

I'm not sure if this is even a sensible question. I was wondering if the following code can ever print a 1. public class Mythread extends Thread { public static void main(String[] args){ Mythread a=new Mythread(); Mythread b=new Mythread(); a.start(); b.start(); new Mythread().start(); new Mythread().start(); new Mythread().start(); } public void run(){ try{ line 1:int count=0; Thread.sleep(1000); System.out.println(count); count++; Thread.sleep(1); }catch(InterruptedException ie){ ...

4. Threads and local variables    coderanch.com

Let's open up Henry's point with a couple examples. Here the local variable map is pretty safe because we create the map locally, use it locally and don't let anybody else see it. public void doSomething() { Map localMap = new HashMap(); do something with the map } But in the next one, we don't know who else might be using ...

5. Accessing a static method with the local variable of java.text.SimpleDateFormat by multiple threads    coderanch.com

There is no thread-safety problem with the original code you posted, at least not associated with the SimpleDateFormat. Each thread makes a separate call to the getTimeStampAsString() method, and each time the method is called it creates a new SimpleDateFormat object. This object is independent for each method call, not shared between them so there is no chance of the object's ...

6. Thread variables, local or shared    coderanch.com

I'm new at Java but thought that this would be the best place to ask my question. My app will run some threads and I'm testing one thread class now. I'm now confused about which of the class variables are local and which are shared among instances of the thread. In the below heuristic snippet I thought that "secondVariable" would be ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.