Java Threads - Get running threads  
Author Message
Pedro Pinto





PostPosted: 2008-4-8 17:42:00 Top

java-programmer, Java Threads - Get running threads Hy there,

I'm building an application that creates a thread. This thread creates
other threads to perform several tasks.

My question is simple. Being this main thread created in a JSP page,
and still running after the user logs out, how can i get the current
status of the thread? I would like for the user, when he logs on the
application, to verify if the thread is active, that is, the current
status.

I can't seem to be able to get the thread once it is initialized.

Thanks in advance for any help.

Regards

Pedro Pinto
 
Hugo





PostPosted: 2008-4-9 2:07:00 Top

java-programmer >> Java Threads - Get running threads On Apr 8, 2:42 am, Pedro Pinto <email***@***.com> wrote:
> Hy there,
>
> I'm building an application that creates a thread. This thread creates
> other threads to perform several tasks.
>
> My question is simple. Being this main thread created in a JSP page,
> and still running after the user logs out, how can i get the current
> status of the thread? I would like for the user, when he logs on the
> application, to verify if the thread is active, that is, the current
> status.
>
> I can't seem to be able to get the thread once it is initialized.
>
> Thanks in advance for any help.
>
> Regards
>
> Pedro Pinto

Hi Pedro:

I am not sure if I completely understand your questions.

Examples of thread details that can be listed are:

Thread.getName(), Thread.isAlive() etc; further info at:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html

Why do you want to show the use the status of the thread?
 
Arne Vajh鴍





PostPosted: 2008-4-9 7:44:00 Top

java-programmer >> Java Threads - Get running threads Pedro Pinto wrote:
> I'm building an application that creates a thread. This thread creates
> other threads to perform several tasks.
>
> My question is simple. Being this main thread created in a JSP page,
> and still running after the user logs out, how can i get the current
> status of the thread? I would like for the user, when he logs on the
> application, to verify if the thread is active, that is, the current
> status.
>
> I can't seem to be able to get the thread once it is initialized.

You need to store a reference to the thread somewhere.

Like saving it in application with username as key.

BTW, it is very bad practice to have JSP pages start threads.

Arne
 
 
Lew





PostPosted: 2008-4-9 7:57:00 Top

java-programmer >> Java Threads - Get running threads Arne Vajh酶j wrote:
> BTW, it is very bad practice to have JSP pages start threads.

Excellent point. In fact, it's somewhat bad practice to have any explicit
Java scriptlet in a JSP. It is better to refactor it according to what Sun
calls the "Model 2" model-view-controller (MVC) architecture, by hand or with
Struts, or to use JSF which implements a full-scale MVC pattern via its
backing beans.

--
Lew