• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/15

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

15 Cards in this Set

  • Front
  • Back

If a class has a synchronized method and non-synchronized method, can multiple threads execute the non-synchronized methods?

Yes. If a class has a synchronized and non-synchronized methods, multiple threads can access the non-synchronixed methods.

If a thread goes to sleep does it hold the lock?

Yes when a thread goes to sleep, invoked by Thread.sleep(xx) it holds a lock.

Can a thread hold multiple locks at the same time?

Yes. A thread can hold multiple locks at the same time. Once a thread acquires a lock and enters into the synchronized method / block, it may call another synchronized method and acquire a lock on another object.

Can a thread call multiple synchronized methods on the object of which it holds a lock?

Yes. Once a thread acquires a lock in some object, it may call any other synchronized method of that same object using the lock that it already holds. The locks are Reentarant.

Can static methods be synchronized?

Yes. Static methods are class methods and have only one copy of static data for the class, only one lock for the entire class is required. Every class in java is represented by java.lang.Class instance. The lock on this instance is used to synchronize the static methods.

Can two threads call two different static synchronized methods of the same class?

No. The static synchronized methods of the same class always block each other as only one lock per class exists.So no two static synchronized methods can execute at the same time.

For a single calling thread, does a static synchronized method block a non-static synchronized method?

No, the thread executing the static synchronized method holds a lock on the class and the thread executing the non-satic synchronized method holds the lock on the object on which the method has been called, these two locks are different and these threads do not block each other.

Once a thread has been started can it be started again?

No. Only a thread can be started only once in its lifetime. If you try starting a thread which has been already started once an IllegalThreadStateException is thrown, which is a runtime exception. A thread in runnable state or a dead thread can not be restarted.

What are the methods of the thread class used to schedule the threads?

sleep(long millis)


yield()


join()


setPriority(int priority)


wait()


notify()


notifyAll()

Which thread related methods are available in Object class?

wait()


notify()


notifyAll()

List the methods which when called the thread does not release the locks held?

join()


sleep()


yield()

List the methods which when called on the object the thread releases the locks held on that object?

notify()


notifyAll()


wait()

Does each thread has its own thread stack?

Yes each thread has its own call stack

What is thread starvation?

In a multi-threaded environment thread starvation occurs if a low priority thread is not able to run or get a lock on the resoruce because of presence of many high priority threads. This is mainly possible by setting thread priorities inappropriately.

What is threadLocal variable?

ThreadLocal is a class. If a variable is declared as threadLocal then each thread will have a its own copy of variable and would not interfere with the other's thread copy. Typical scenario to use this would be giving JDBC connection to each thread so that there is no conflict.