// 定时器插件 SchedulerPlugin sp = new SchedulerPlugin(); Runnable task = new Task(); sp.fixedRateSchedule(task, 10); me.add(sp);
public class Task implements Runnable{ @Override public void run() { /* * 1. 取得过期的挂单 * 2. 更改状态为已过期 * 3. 解冻保证金 */ System.out.println("22222222222"); BigDecimal counts = null; BigDecimal userId = null; List<Post> list = Post.dao.getOutDatedPosts(); /*System.out.println(list.size()); for (Post post : list) { counts = post.getCounts(); userId = post.getUserId(); post.setStatusP("4"); post.update(); Balance b = Balance.dao.findByUserId(userId); BigDecimal amount = counts.multiply(Data.getReceivem()); b.setValidAmount(b.getValidAmount().add(amount)); b.setFreezeAmount(b.getFreezeAmount().subtract(amount)); b.update(); }*/ } }
服务器运行后,出现异常。
22222222222 java.lang.NullPointerException at com.jfinal.plugin.activerecord.Model.find(Model.java:554) at com.jfinal.plugin.activerecord.Model.find(Model.java:571) at com.fw.model.Post.getOutDatedPosts(Post.java:280) at com.fw.util.Task.run(Task.java:22) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) 八月 30, 2016 2:27:19 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 八月 30, 2016 2:27:19 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 八月 30, 2016 2:27:19 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 7909 ms 22222222222 22222222222 22222222222 22222222222 22222222222
我发现是查询那点出的问题。就把那段代码放到一个 Controller 中验证能够正常使用。说明这个查询没错啊,为什么会爆出这种异常?
此时服务还没有完全启动,db还没连呢 - -