多线程及定时器
来源:互联网 发布:最新安卓java模拟器 编辑:程序博客网 时间:2024/06/15 18:23
1、在Thread子类覆盖的run方法里编写运行代码
2、在传递给Thread对象的Runnable对象的run方法里编写运行代码。
通过查看Thread类的run方法源码可知,这两种方式都是在调用Thread的run方法,如果Thread类的run方法没有被覆盖,并且为该Thread对象传递了一个Runnable对象,该run方法会调用Runnable对象的run方法。
如果在Thread子类中覆盖了run方法,也为Thread传递了一个runnable对象,那么线程执行时是运行哪个run方法,运行的是子类中覆盖了Thread的run方法。
Timer定时器
public class TraditionalTimerTest { private static int count = 0; public static void main(String[] args) { class MyTimerTask extends TimerTask { @Override public void run() { count = (count+1)%2; System.out.println("bombing!"); new Timer().schedule(new MyTimerTask(), 2000+2000*count); } } new Timer().schedule(new MyTimerTask(), 2000); while (true) { System.out.println(new Date().getSeconds()); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }}
quartz
0 0
- 多线程及定时器
- (转载)android多线程及定时器处理方式
- 多线程 定时器
- 多线程-定时器
- 多线程定时器
- 定时器与多线程
- C#多线程实现定时器
- 多线程:4种定时器
- 多线程:4种定时器
- QT多线程与定时器
- QT多线程与定时器
- c#多线程定时器
- 定时器非多线程
- 多线程 : 定时器基本用法
- 多线程 定时器 Timer
- 多线程之定时器任务
- C# 多线程 定时器
- timerfd实现多线程定时器
- Java获取当天的起始时间和结束时间
- missing content stream
- PHP打印一个变量
- rror LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC
- spring框架_06 AOP
- 多线程及定时器
- 【原创】新人android逆向破解的第一次感悟和思路分享
- CreateProcess函数详解
- 黑马程序员_集合TreeMap练习:获取某一字符串的字母出现的次数
- linux下安装jdk+配置多个tomcat
- IOS添加pch预编译文件
- Needleman-Wunsch 算法和Smith-Waterman算法
- #define
- spring data solr 之多核配置