Lombok(1.14.8) - @Synchronized

@Synchronized

@Synchronized,实现同步。

package com.huey.lombok;

import java.util.Date;

import lombok.Synchronized;

public class SynchronizedExample implements Runnable {

    @Override
public void run() {
sayHello();
} @Synchronized
public void sayHello() {
System.out.println("hello, " + Thread.currentThread().getName() + "! Now is " + new Date());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
SynchronizedExample foo = new SynchronizedExample();
new Thread(foo).start(); // [OUTPUT]: hello, Thread-0! Now is Sat Aug 01 10:55:08 CST 2015
new Thread(foo).start(); // [OUTPUT]: hello, Thread-1! Now is Sat Aug 01 10:55:11 CST 2015
}
}
上一篇:shell脚本 Linux系统安全监测


下一篇:linux 系统性能指标采样脚本