package com.example.demo.tool; import lombok.SneakyThrows; /** * 实现了Runnable接口 */ public class TaskRunnable implements Runnable { int count = 0; @SneakyThrows @Override public synchronized void run() { while (true){ if(count > 5){ break; } System.out.print(String.valueOf(count) + "\r\n"); count ++; wait(500); } } }