代码:

1、

timer5 = new Timer();
Calendar now=Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY,new Date().getHours());
now.set(Calendar.MINUTE, new Date().getMinutes());
now.set(Calendar.SECOND, new Date().getSeconds()+10);
now.set(Calendar.MILLISECOND, 0);
System.out.print("\n时间now为: "+now.toString()+" 毫秒数:"+now.getTimeInMillis());
Date operTime=new Date(now.getTimeInMillis());
System.out.println("\n预设初始执行时间为: "+operTime);

timer.schedule(task,operTime,1);

2、

private TimerTask task = new TimerTask() {
public void run() {
scoreCount();
System.gc();
}
};

在2、中不添加System.gc()时,tomcat会出现自动关闭的问题,同时产生了一个hs_err_pid12588.log文件,内容如下

#
# An unexpected error has been detected by Java Runtime Environment:
#
# java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space?
#
# Internal Error (allocation.cpp:120), pid=12588, tid=9048
# Error: ChunkPool::allocate
#
# Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode windows-x86)
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

--------------- T H R E A D ---------------

Current thread (0x02308400): VMThread [stack: 0x48870000,0x488c0000] [id=9048]

Stack: [0x48870000,0x488c0000]
[error occurred during error reporting (printing stack bounds), id 0xc0000005]

VM_Operation (0x6967f574): DeoptimizeFrame, mode: safepoint, requested by thread 0x4ab02000


--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x4a788000 JavaThread "Thread-63821" daemon [_thread_in_native, id=8064, stack(0x7a900000,0x7a950000)]
0x5d569c00 JavaThread "Thread-63687" daemon [_thread_blocked, id=11108, stack(0x7de50000,0x7dea0000)]
0x5d5b4400 JavaThread "Thread-63686" daemon [_thread_in_native, id=9124, stack(0x7ddc0000,0x7de10000)]