You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by micael <ca...@harbornet.com> on 2002/12/09 02:17:07 UTC

Threads of Control

Can a servlet start an application on a server which is available to a user 
on the server machine?  Something, i.e., like the following:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AppCtrl extends HttpServlet implements Runnable {
   private boolean change;
   private Thread ctrl;
   private App [] app;

   public void init() throws ServletException() {
     ctrl = new Thread(this);
     ctrl.setPriority(Thread.MIN_PRIORITY);
     ctrl.start();
   }

   public void run() {
     while(true) {
       if(AppProps.change()) {
         app = AppProps.changes();
         for(int i = 0; i < app.length; i++) {
           AppManager.implementChange(app[i]);
           try {
             ctrl.sleep(200); // .2 second break between changes.
           } catch (InterruptedException ignored) {
           }
         }
       }
     }
   }
}


Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank you 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--> Starting and Stopping Applications in Servlets: Re: Threads of Control

Posted by micael <ca...@harbornet.com>.
At 05:17 PM 12/8/2002 -0800, you wrote:
>Can a servlet start an application on a server which is available to a 
>user on the server machine?  Something, i.e., like the following:
>
>import java.io.*;
>import java.util.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public class AppCtrl extends HttpServlet implements Runnable {
>   private boolean change;
>   private Thread ctrl;
>   private App [] app;
>
>   public void init() throws ServletException() {
>     ctrl = new Thread(this);
>     ctrl.setPriority(Thread.MIN_PRIORITY);
>     ctrl.start();
>   }
>
>   public void run() {
>     while(true) {
>       if(AppProps.change()) {
>         app = AppProps.changes();
>         for(int i = 0; i < app.length; i++) {
>           AppManager.implementChange(app[i]);
>           try {
>             ctrl.sleep(200); // .2 second break between changes.
>           } catch (InterruptedException ignored) {
>           }
>         }
>       }
>     }
>   }
>}
>
>
>Micael
>
>-------------------------------------------------------
>
>This electronic mail  transmission and any accompanying documents contain 
>information belonging to the sender which may be confidential and legally 
>privileged.  This information is intended only for the use of the 
>individual or entity to whom this electronic mail transmission was sent as 
>indicated above. If you are not the intended recipient, any disclosure, 
>copying, distribution, or action taken in reliance on the contents of the 
>information contained in this transmission is strictly prohibited.  If you 
>have received this transmission in error, please delete the 
>message.  Thank you
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>

Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Threads of Control

Posted by Jeremy Joslin <je...@spotlife.com>.
Ummmm errrr...sure you could do that but you should ask yourself "is this
the right thing to do?"  If the sample code you provided is similar to what
you're trying to implement I would recommend that you right your own
Runnable object and control it's lifetime using a ServeltContextListener
object.  Or at least define the Runnable object as a private inner class of
the Servlet so you're not exposing a public method that isn't intended to be
called from outside the servlet.  Just my 2 cents...

Jeremy

> -----Original Message-----
> From: micael [mailto:caraunltd@harbornet.com]
> Sent: Sunday, December 08, 2002 5:17 PM
> To: Tomcat Users List
> Subject: Threads of Control
> 
> Can a servlet start an application on a server which is available to a
> user
> on the server machine?  Something, i.e., like the following:
> 
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> public class AppCtrl extends HttpServlet implements Runnable {
>    private boolean change;
>    private Thread ctrl;
>    private App [] app;
> 
>    public void init() throws ServletException() {
>      ctrl = new Thread(this);
>      ctrl.setPriority(Thread.MIN_PRIORITY);
>      ctrl.start();
>    }
> 
>    public void run() {
>      while(true) {
>        if(AppProps.change()) {
>          app = AppProps.changes();
>          for(int i = 0; i < app.length; i++) {
>            AppManager.implementChange(app[i]);
>            try {
>              ctrl.sleep(200); // .2 second break between changes.
>            } catch (InterruptedException ignored) {
>            }
>          }
>        }
>      }
>    }
> }
> 
> 
> Micael
> 
> -------------------------------------------------------
> 
> This electronic mail  transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged.  This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly prohibited.  If you
> have received this transmission in error, please delete the message.
> Thank you
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>