This article is based on the Java doubts this book, made notes.
ebook See:http://download.csdn.net/detail/u010378705/7527721 Puzzle
Start the thread starting method (), written as run ();
PS: Enhancement (monitor) lock needs further understanding.
Puzzle the issue of locking in Threads. Understanding is not profound.
Puzzle 78
reflection can cause access to members of non-public types in other packages. Causes the execution period to be abnormal.
Puzzle
Masking: The Thread.Sleep () method obscures the custom method.
Puzzle
Reflection: How to instantiate a non-static inner class and a static inner class.
The
Riddle of Bayi
System.out.write (): Does not voluntarily refresh itself. Need to use System.out.flush () to refresh.
Puzzle
the problem of process use is not understood.
The riddle of the
puzzle
The relationship between singleton patterns and serialization.
public class Dog extends Exception {private static final long Serialversionuid = 1l;publ IC static final Dog INSTANCE = new Dog ();p rivate Dog () {}public String toString () {return ' Woof ';}
Private Object Readresolve () {return INSTANCE;}}
Exception implements the serializable, there must be a Readresolve method to return its unique instance.
Otherwise it can be deserialized to get multiple objects.
Puzzle
thread.interrupted () method. Clears the interrupt state of the current thread.
The thread.isinterrupted () method is simply the query interrupt state.
Puzzle
Waiting for a background thread during the initialization of a class is very likely to cause a deadlock.
public class Lazy {private static Boolean initialized = false;static {thread T = new Thread (new Runnable () {public void Ru N () {initialized = true;}}); T.start (); try {t.join ();} catch (Interruptedexception e) {e.printstacktrace ()}} public static void Main (string[] args) {System.out.println (initialized);}}
1. When the main thread calls the Lazy.main method, it checks whether the lazy class has been initialized, not at this time, so the main thread will record that the initialization is currently in progress. and initialize the class.
2. The main thread sets the value of initialized to False to create a background thread. The change background thread sets initialized to true, at which point the main thread waits for the background threads to finish running.
3. However, when the background thread calls the Run method. Before lazy.initialized is set to true, the lazy class is also checked for initialization.
This class is being initialized by the main thread.
The background thread waits until the initialization is complete.
4. The main thread is also waiting for the background thread to end. Cause a deadlock.
Java puzzle Eight: A lot of other library mysteries