系統分析---入門(如何確定java應用的入口)

一、場景

A拿到一個java的開源項目(如eclipse項目),此開源項目可以啓動,並且已經拿到了該項目的源碼,小A想對這個開源項目進行一次系統的學習。

二、問題:

這時候,小A遇到了一個問題,如何確定該項目的入口? 

三、技巧:JPSjstack應用

           如果是一般的web應用還好說,我們可以不關心應用的入口,但現在是eclipse,所以能確定其程序的主入口對於分析該程序很有幫助。

           那麼如何確定其入口呢。由於此項目是java項目,我們都知道java程序的入口方法是main方法。可以以此作爲突破口,從線程棧中找到main對應的線程,不就找到該程序的入口了嗎。

四、實踐

1JPS確定該進程的ID

首先啓動該程序(eclipse),然後使用jps確定該進程的ID:

C:\Users\Administrator>JPS

4232

2、使用jstack導出線程的棧信息

C:\Users\Administrator>jstack 4232 > threadDump.log

3、查看threadDump.log

"main" prio=6 tid=0x020a9800 nid=0xdb4 runnable [0x0012f000]
   java.lang.Thread.State: RUNNABLE
at org.eclipse.swt.internal.win32.OS.WaitMessage(Native Method)
at org.eclipse.swt.widgets.Display.sleep(Display.java:4652)
at org.eclipse.ui.application.WorkbenchAdvisor.eventLoopIdle(WorkbenchAdvisor.java:364)
at org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor.eventLoopIdle(IDEWorkbenchAdvisor.java:917)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2702)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

找到main線程,注意最後一句

at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
由此可以確定eclipse的程序入口,好了,開始你的eclipse源碼之旅吧

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章