比较有意思的一段代码,能够先运行看效果再将注释取消后看运行效果,上代码多线程
- public class StaticBlockTest implements Runnable{
-
- static{
- if(true){
- System.out.println("test");
- }
-
- }
-
- @Override
- public void run() {
-
- System.out.println("run");
- }
-
- public static void main(String[] args) {
- StaticBlockTest s = new StaticBlockTest();
- StaticBlockTest s1 = new StaticBlockTest();
- Thread t1 = new Thread(s);
- Thread t2 = new Thread(s1);
-
-
- t1.start();
- t2.start();
-
- }
-
-
-
- }