日期:2014-05-20  浏览次数:20706 次

java cpu占用高
top发现某个java进程cpu 99%,socket短连接服务程序,但是还是能够正常工作,响应也很快。
netstat查了一下,无异常情况,端口均能快速关闭。
请高手告知如何解决
jstack pid如下

ull thread dump Java HotSpot(TM) Server VM (1.6.0_02-b05 mixed mode):

"Keep-Alive-Timer" daemon prio=10 tid=0x87252c00 nid=0x7ec4 waiting on condition [0x87d98000..0x87d98f20]
  java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at sun.net.www.http.KeepAliveCache.run(KeepAliveCache.java:149)
at java.lang.Thread.run(Thread.java:619)

"Attach Listener" daemon prio=10 tid=0x089aa000 nid=0x7e45 runnable [0x00000000..0x00000000]
  java.lang.Thread.State: RUNNABLE

"pool-1-thread-30" prio=10 tid=0x08257000 nid=0x240d waiting on condition [0x87d47000..0x87d47fa0]
  java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x47343388> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:358)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:946)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:906)
at java.lang.Thread.run(Thread.java:619)

"pool-1-thread-29" prio=10 tid=0x08256400 nid=0x240c waiting on condition [0x87cf6000..0x87cf6f20]
  java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x47343388> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:358)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:946)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:906)
at java.lang.Thread.run(Thread.java:619)


。。。。

"Finalizer" daemon prio=10 tid=0x0811fc00 nid=0x23ad in Object.wait() [0x86edc000..0x86edd020]
  java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x47385cb0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
- locked <0x47385cb0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x0811c000 nid=0x23ac in Object.wait() [0x86e8b000..0x86e8bfa0]
  java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x473861e0> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x473861e0> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x08119400 nid=0x23ab runnable 

"GC task thread#0 (ParallelGC)" prio=10 tid=0x0805e800 nid=0x23a9 runnable 

"GC task thread#1 (ParallelGC)" prio=10 tid=0x0805f800 nid=0x23aa runnable 

"VM Periodic Task Thread" prio=10 tid=0x0813cc00 nid=0x23b2 waiting on condition 

JNI global references: 999

------解决方案--------------------
看看短连接 是不是连接数过多未关闭了?linux下还有个问题就是:句柄数过多,默认好像是1024,改成4096,,