我在tomcat中有30個WAR,它們之間存在依賴關係。所以我們有一個servlet按順序部署它們。現在我想先按順序部署所需的應用程序,然後再並行地部署它們。Tomcat使用ManagerServlet的多線程部署
我的代碼如下所示。
public class MyDeployerServlet extends ManagerServlet {
...
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
...
if(count < serialContexts){
super.deploy(writer, context, contextName, null, false, sm);
count++;
} else {
MyAsyncDeployer deployer = new MyAsyncDeployer(writer, context, contextName, null, false, sm);
Thread deployerThread = new Thread(deployer);
deployerThread.start();
}
}
MyAsyncDeployer運行的代碼是:
public class MyAsyncDeployer extends MyDeployerServlet implements Runnable{
private PrintWriter writer;
private String config;
private ContextName context;
private String war;
private boolean update;
private StringManager sm;
public MyAsyncDeployer(PrintWriter writer, String config, ContextName context, String war, boolean update,
StringManager sm) {
this.writer = writer;
this.config = config;
this.context = context;
this.war = war;
this.update = update;
this.sm = sm;
}
public void run() {
super.deploy(writer, config, context, null, false, sm);
}
當我打電話,串行部署去罰款,但多線程部署拋出異常下面。
Exception in thread "Thread-9" java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:123)
at javax.servlet.GenericServlet.log(GenericServlet.java:188)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:834)
at com.example.servlet.MyAsyncDeployer.run(MyAsyncDeployer.java:30)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-10" java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:123)
at javax.servlet.GenericServlet.log(GenericServlet.java:188)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:834)
at com.example.servlet.MyAsyncDeployer.run(MyAsyncDeployer.java:30)
at java.lang.Thread.run(Thread.java:745)
我很無能什麼是在這裏失蹤,我在我的線程中使用相同的對象引用。如果這可以在多線程的方式進行部署?
我也打開任何其他方法,這個想法是部署前幾個上下文,然後並行休息。 – Pankaj
什麼類型的依賴關係(jar ...) –
@Pankaj我已經更新了我的答案,你可以再試一次嗎? – qwwdfsad