常用模板封装
- forthreat10 创建10个线程
for (int i = 0; i < 10; i++) {
new Thread(() -> {
$END$
}, String.valueOf(i)).start();
}
- newthread 创建线程
new Thread(() -> {
$END$
}, $VAR$).start();
- trylock 可重入锁
lock.lock();
try {
$END$
} catch (Exception e) {
e.printStackTrace();
} finally {
lock.unlock();
}
- tryreadlock 读锁
rwLock.readLock().lock();
try {
$END$
} catch (Exception e) {
e.printStackTrace();
} finally {
rwLock.readLock().unlock();
}
- trywritelock 写锁
rwLock.writeLock().lock();
try {
$END$
} catch (Exception e) {
e.printStackTrace();
} finally {
rwLock.writeLock().unlock();
}
- log 日志
log.info("$END$");
- tsleep 线程睡几秒
try {
TimeUnit.SECONDS.sleep($VAR$);
} catch (InterruptedException e) {
e.printStackTrace();
}
- tryfinally 异常处理finally
try {
$END$
} catch (Exception e) {
e.printStackTrace();
} finally {
}