在linux下运行多线程程序,想查看各个线程的运行情况,怎么办?
Linux下查看某进程的线程状态:
1.jps或top或ps -ef|grep java,找到需要的进程pid;
2.jstack pid,查看pid的所有线程状态信息;
下面为一个示例:进程6798启动了5个线程,其他两个正在跑,另外三个进入了睡眠状态。
[[email protected] topology]# jstack 6798 2015-03-02 09:49:05 Full thread dump Java HotSpot(TM) 64-Bit Server VM (17.1-b03 mixed mode): "pool-1-thread-5" prio=10 tid=0x00007f956c0cb000 nid=0x1a9e runnable [0x00007f95269a9000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at oracle.net.ns.Packet.receive(Unknown Source) at oracle.net.ns.DataPacket.receive(Unknown Source) at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:979) at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:951) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:435) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:182) at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:630) at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:961) at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:532) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1037) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2946) - locked <0x00007f9564b03cf0> (a oracle.jdbc.driver.T4CPreparedStatement) - locked <0x00007f95527be288> (a oracle.jdbc.driver.T4CConnection) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1778) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2211) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095) at org.hibernate.loader.Loader.list(Loader.java:2090) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at com.hc360.storm.dao.BaseDao.query(BaseDao.java:753) at com.hc360.storm.dao.BaseDao.query(BaseDao.java:676) at com.hc360.storm.dao.CompassProdDao.resetFreeBusinComplete(CompassProdDao.java:80) at com.hc360.storm.service.CompassManage.resetBusinCompass(CompassManage.java:621) at com.hc360.storm.service.CompassManage.saveBusinInfo(CompassManage.java:456) at com.hc360.storm.service.CompassManage.initBusinScore(CompassManage.java:215) at com.hc360.storm.service.CompassManage.initUserBusinScore(CompassManage.java:270) at sun.reflect.GeneratedMethodAccessor341.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.hc360.storm.service.BusinessInvocationHandler.invoke(BusinessInvocationHandler.java:42) at $Proxy1.initUserBusinScore(Unknown Source) at com.hc360.storm.newinit.BatchInitUser.initOneUser(BatchInitUser.java:59) at com.hc360.storm.newinit.InitUserTask.run(BatchInitUser.java:91) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) "pool-1-thread-4" prio=10 tid=0x00007f956c0c9800 nid=0x1a9d waiting on condition [0x00007f9526aab000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at com.hc360.storm.newinit.InitUserTask.run(BatchInitUser.java:81) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) "pool-1-thread-3" prio=10 tid=0x00007f956c0c8000 nid=0x1a9c waiting on condition [0x00007f9526bac000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at com.hc360.storm.newinit.InitUserTask.run(BatchInitUser.java:81) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) "pool-1-thread-2" prio=10 tid=0x00007f956c0c6800 nid=0x1a9b waiting on condition [0x00007f9526cad000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at com.hc360.storm.newinit.InitUserTask.run(BatchInitUser.java:81) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) "pool-1-thread-1" prio=10 tid=0x00007f956c0c4800 nid=0x1a9a runnable [0x00007f9526dad000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at oracle.net.ns.Packet.receive(Unknown Source) at oracle.net.ns.DataPacket.receive(Unknown Source) at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.net.ns.NetInputStream.read(Unknown Source) at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:979) at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:951) at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:100) at oracle.jdbc.driver.T4CConnection.do_rollback(T4CConnection.java:474) - locked <0x00007f9552188c00> (a oracle.jdbc.driver.T4CConnection) at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1034) - locked <0x00007f9552188c00> (a oracle.jdbc.driver.T4CConnection) at com.mchange.v2.c3p0.impl.C3P0ImplUtils.resetTxnState(C3P0ImplUtils.java:275) at com.mchange.v2.c3p0.impl.NewPooledConnection.reset(NewPooledConnection.java:388) at com.mchange.v2.c3p0.impl.NewPooledConnection.markClosedProxyConnection(NewPooledConnection.java:362) - locked <0x00007f9552188b70> (a com.mchange.v2.c3p0.impl.NewPooledConnection) at com.mchange.v2.c3p0.impl.NewProxyConnection.close(NewProxyConnection.java:1246) - locked <0x00007f9564a6cbd8> (a com.mchange.v2.c3p0.impl.NewProxyConnection) at org.hibernate.connection.C3P0ConnectionProvider.closeConnection(C3P0ConnectionProvider.java:70) at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:449) at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:404) at org.hibernate.jdbc.ConnectionManager.afterTransaction(ConnectionManager.java:291) at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:221) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:119) at com.hc360.mmt.db.dao.util.MmtSessionFactory.commit(MmtSessionFactory.java:164) at com.hc360.storm.dao.BaseDao.commit(BaseDao.java:1774) at com.hc360.storm.dao.BaseDao.update(BaseDao.java:418) at com.hc360.storm.dao.BaseDao.update(BaseDao.java:372) at com.hc360.storm.dao.CompassProdDao.resetFreeBusinComplete(CompassProdDao.java:100) at com.hc360.storm.service.CompassManage.resetBusinCompass(CompassManage.java:621) at com.hc360.storm.service.CompassManage.saveBusinInfo(CompassManage.java:456) at com.hc360.storm.service.CompassManage.initBusinScore(CompassManage.java:215) at com.hc360.storm.service.CompassManage.initUserBusinScore(CompassManage.java:270) at sun.reflect.GeneratedMethodAccessor341.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.hc360.storm.service.BusinessInvocationHandler.invoke(BusinessInvocationHandler.java:42) at $Proxy1.initUserBusinScore(Unknown Source) at com.hc360.storm.newinit.BatchInitUser.initOneUser(BatchInitUser.java:59) at com.hc360.storm.newinit.InitUserTask.run(BatchInitUser.java:91) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
时间: 2024-10-10 14:58:44