Threading in an Application Server

前端 未结 6 1263
礼貌的吻别
礼貌的吻别 2021-02-19 21:41

I have a Java program/thread that I want to deploy into an Application Server (GlassFish). The thread should run as a \"service\" that starts when the Application Server starts

6条回答
  •  情深已故
    2021-02-19 21:48

    Create a servlet whose init method starts a thread which is the main program.

    public void init() throws ServletException {
        mailThread = new MailSendThread();
        mailThread.start();
    }
    

    In our application's web.xml file add a servlet that includes a load-on-startup element where the number is the order in which it starts.

    
        Mail Sending Servlet
        MailServlet
        2
    
    

提交回复
热议问题