When different threads access a static method, are objects declared in that method local or shared between threads in java?
Also,  is it safe to call thread.interrupt() on a thread that is doing i/o?
Objects declared inside a static method are not shared between threads.  Objects defined outside the method as static are shared. 
So:
private static Object thisIsShared;
public static void myMethod() {
    Object thisIsNotShared = new Object();
}
If you're going to be calling interrupt() on threads doing I/O you should look at using classes that implement the InterruptableChannel interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With