线程run方法里方法执行问题求大神骂

程序员小周周 2015-10-29 10:14:11
public void run() {
try {
doExportFile();
preReportDel();

appExpFileInfo odr = (appExpFileInfo) preReportDownload();
service.save(odr);

// service.remove(del.getFileName());
} catch (Exception e) {
e.printStackTrace();
status = DownloadThreadFenboCon.status_completed;
throw new BizException(1, 0, "2002", "下载失败!");
}
status = DownloadThreadFenboCon.status_completed;
synchronized (lock) {
lock.notify();
}
以上run方法如果debugge一步一步走,可以执行完doExportFile();再执行 preReportDel();再执行 preReportDownload();

如果不debugge,那么方法doExportFile();方法执行5遍, preReportDel();再执行5遍 preReportDownload();再执行5便

就是一步一步走的话控制台打日志是123,123,123,123,123
不打断点是11111,22222,33333 这个是怎么回事,再线等大神回答。
...全文
196 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dracularking 2015-11-02
  • 打赏
  • 举报
回复
读取文件个数是怎么实现的?和这三个方法有什么联系
程序员小周周 2015-11-01
  • 打赏
  • 举报
回复
引用 7 楼 u012214165 的回复:
[quote=引用 6 楼 dracularking 的回复:] 如果要达到单步执行时的效果,试试同步下这三个方法的执行 class MyThread extends Thread { ... public void run(){ synchronized(MyThread.class) { method1(); method2(); method3(); } }
还在么?确实可以了[/quote]
引用 6 楼 dracularking 的回复:
如果要达到单步执行时的效果,试试同步下这三个方法的执行 class MyThread extends Thread { ... public void run(){ synchronized(MyThread.class) { method1(); method2(); method3(); } }
为何这样改完后我的读取文件夹文件个数打包不好用了,没改之前是好用的。
程序员小周周 2015-11-01
  • 打赏
  • 举报
回复
引用 6 楼 dracularking 的回复:
如果要达到单步执行时的效果,试试同步下这三个方法的执行 class MyThread extends Thread { ... public void run(){ synchronized(MyThread.class) { method1(); method2(); method3(); } }
还在么?确实可以了
dracularking 2015-11-01
  • 打赏
  • 举报
回复
如果要达到单步执行时的效果,试试同步下这三个方法的执行 class MyThread extends Thread { ... public void run(){ synchronized(MyThread.class) { method1(); method2(); method3(); } }
程序员小周周 2015-11-01
  • 打赏
  • 举报
回复
引用 2 楼 defonds 的回复:
CPU 对线程的调度还是很合理的。 doExportFile(); preReportDel(); preReportDownload(); 这三个方法应该执行的时间不短,所以你不人工干预(debug)的话,每个线程抢到 cpu 的机会基本是均等的。
那这个问题怎么解决呢??我现在很烦恼啊
  • 打赏
  • 举报
回复
让线程内部的方法同步执行呗
Defonds 2015-10-30
  • 打赏
  • 举报
回复
CPU 对线程的调度还是很合理的。 doExportFile(); preReportDel(); preReportDownload(); 这三个方法应该执行的时间不短,所以你不人工干预(debug)的话,每个线程抢到 cpu 的机会基本是均等的。
zhouxingchi9527 2015-10-29
  • 打赏
  • 举报
回复
不太懂,开了多个线程吗?debug是你想执行哪个线程就执行哪个线程,不打断点就是哪个线程抢到cpu哪个线程执行

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧