Re: HOW CAN I USE THREADS IN TOMCAT

2003-11-03 Thread IvanLatysh
Hello, Prince!
You wrote to Tomcat Users List [EMAIL PROTECTED] on Sat, 1 Nov 2003 13:21:42 +0530:

 P Hi,
 P  I need to send a mail automatically at 10 minutes interval. how can
 P i do this? how can i activate threads in tomcat?

Tomcat is a Java application, there are no difference of using threads with Tomcat or 
without it.
Simply expand Thread class, and run your thread.
But don't forget to notify and kill your thread when Tomcat is shutting down.

Here is a link that might help you.
http://developer.java.sun.com/developer/codesamples/thrds.html

---
Regards
Ivan[a]yourmail.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: HOW CAN I USE THREADS IN TOMCAT

2003-11-03 Thread Mufaddal Khumri
Hi,

I have an instance of MyMailScheduler - mmsched in a ContextListener 
class for my webapp. mmsched spawns threads to do some work regarding 
sending emails. In my contextDestroy method I do : mmsched = null;

I was under the impression that if tomcat was shutdown or the webapp 
was stopped my threads would be automatically killed since mmsched 
would be garbage collected. Am I understanding this right or do I need 
to do something else ?

 My webapp does two mail related tasks for two different sets of data. 
Both tasks are identical and therefore I spawn two threads. The two 
threads do not share any data structures. Also do I need to make the 
run() method synchronized ?

Thanks.

On Monday, November 3, 2003, at 08:45  PM, IvanLatysh wrote:

Hello, Prince!
You wrote to Tomcat Users List [EMAIL PROTECTED] on 
Sat, 1 Nov 2003 13:21:42 +0530:

 P Hi,
 P  I need to send a mail automatically at 10 minutes interval. how 
can
 P i do this? how can i activate threads in tomcat?

Tomcat is a Java application, there are no difference of using threads 
with Tomcat or without it.
Simply expand Thread class, and run your thread.
But don't forget to notify and kill your thread when Tomcat is 
shutting down.

Here is a link that might help you.
http://developer.java.sun.com/developer/codesamples/thrds.html
---
Regards
Ivan[a]yourmail.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: HOW CAN I USE THREADS IN TOMCAT

2003-11-03 Thread Mufaddal Khumri
Hi,

The problem is that stop / suspend are deprecated. The destroy() method 
has yet not been implemented ? What does one do then?

I have a solution -

Keep a reference to the instances of the threads spawned in a 
hashtable. In contextDestroy make all these references null . Will this 
solution work ?

Thanks.

On Monday, November 3, 2003, at 09:27  PM, Shapira, Yoav wrote:

Howdy,

I have an instance of MyMailScheduler - mmsched in a ContextListener
class for my webapp. mmsched spawns threads to do some work regarding
sending emails. In my contextDestroy method I do : mmsched = null;
mmsched should have a close()/stop()/shutdown() method which stops its
threads.  You call this method, and then set mmsched to null.
I was under the impression that if tomcat was shutdown or the webapp
was stopped my threads would be automatically killed since mmsched
would be garbage collected. Am I understanding this right or do I need
to do something else ?
The JVM can't stop non-daemon threads.  Either make mmsched spawn 
daemon
threads, or make the mmsched stop() method interrupt and stop all its
threads.

 My webapp does two mail related tasks for two different sets of data.
Both tasks are identical and therefore I spawn two threads. The two
threads do not share any data structures. Also do I need to make the
run() method synchronized ?
You don't need to make the run() method synchronized.

Yoav Shapira



This e-mail, including any attachments, is a confidential business 
communication, and may contain information that is confidential, 
proprietary and/or privileged.  This e-mail is intended only for the 
individual(s) to whom it is addressed, and may not be saved, copied, 
printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your 
computer system and notify the sender.  Thank you.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


HOW CAN I USE THREADS IN TOMCAT

2003-11-01 Thread Prince
Hi,
 I need to send a mail automatically at 10 minutes interval. how can i do
this? how can i activate threads in tomcat?
regards
Prince

- Original Message -
From: Bill Barker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, November 01, 2003 1:00 PM
Subject: Re: Opinions


 The recent port of the 3.3 variable-substitution to Tomcat 5 may very well
 solve your problems here :).  The ports are supposed to move to
 commons-digester, so should be available in 4.1.30 as well.

 Francois JEANMOUGIN [EMAIL PROTECTED] wrote in
 message
 news:[EMAIL PROTECTED]


  Hu! It's in early developments or is it suitable for production ?
 
  It's ready for production.  People are already using it in production
  with tomcat 5.  Of course, I'm biased ;)

 Well, there is that beta flag in front of tomcat5 that tell me that your
 opinion is more than biased :). Of course, I saw a mail telling that the
 beta flag is related to specification instability (not code), anyway...

  It's a Developer, rather than Sysadmin, option.  Chances are you won't
  need to worry about it as you'll use commons-daemon with tomcat, which
  already does the required jsvc invocation for you.

 Well, that does not help that much. I hope that there will be a
 configuration scheme that'll let easily define user/group/port and so on
for
 the connectors. Just waiting for a sysadmin point of view :).

 Thanks,

 François.




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: HOW CAN I USE THREADS IN TOMCAT

2003-11-01 Thread Eric C
Use cron under unix and/or a java app that would use Javamail classes.
Of course you can do it inside a servlet.

- Original Message -
From: Prince [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Saturday, November 01, 2003 8:51 AM
Subject: HOW CAN I USE THREADS IN TOMCAT


 Hi,
  I need to send a mail automatically at 10 minutes interval. how can i do
 this? how can i activate threads in tomcat?
 regards
 Prince

 - Original Message -
 From: Bill Barker [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Saturday, November 01, 2003 1:00 PM
 Subject: Re: Opinions


  The recent port of the 3.3 variable-substitution to Tomcat 5 may very
well
  solve your problems here :).  The ports are supposed to move to
  commons-digester, so should be available in 4.1.30 as well.
 
  Francois JEANMOUGIN [EMAIL PROTECTED] wrote in
  message
 
news:[EMAIL PROTECTED]
 
 
   Hu! It's in early developments or is it suitable for production ?
  
   It's ready for production.  People are already using it in production
   with tomcat 5.  Of course, I'm biased ;)
 
  Well, there is that beta flag in front of tomcat5 that tell me that your
  opinion is more than biased :). Of course, I saw a mail telling that the
  beta flag is related to specification instability (not code), anyway...
 
   It's a Developer, rather than Sysadmin, option.  Chances are you won't
   need to worry about it as you'll use commons-daemon with tomcat, which
   already does the required jsvc invocation for you.
 
  Well, that does not help that much. I hope that there will be a
  configuration scheme that'll let easily define user/group/port and so on
 for
  the connectors. Just waiting for a sysadmin point of view :).
 
  Thanks,
 
  François.
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: HOW CAN I USE THREADS IN TOMCAT

2003-11-01 Thread Erik Wright
A servlet is just a Java class. You can do anything you can do with the 
java language, including start threads. The following starts a thread 
that runs some task every 10 minutes. The thread is started in the 
servlet init method. I choose to set the thread to daemon mode, meaning 
that when the main thread of execution shuts down the mailer thread will 
automatically be killed. Otherwise you need to be sure to keep track of 
it and be sure to signal it to shutdown in your Servlet.destroy method.

public class MyServlet extends HttpServlet
{
   private static class MailerThread extends Thread
   {
  public void run ()
  {
 while (true)
 {
 // do something
synchronized (this)
{
   wait (10*60*1000);
}
 }
  }
   }
   // the servlet init method
   public void init ()
   {
  MailerThread thread = new MailerThread ();
  thread.setDaemon (true);
  thread.start ();
   }
   // ... doGet, etc. ...
}
-Erik

Eric C wrote:

Use cron under unix and/or a java app that would use Javamail classes.
Of course you can do it inside a servlet.
- Original Message -
From: Prince [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Saturday, November 01, 2003 8:51 AM
Subject: HOW CAN I USE THREADS IN TOMCAT
 

Hi,
I need to send a mail automatically at 10 minutes interval. how can i do
this? how can i activate threads in tomcat?
regards
Prince
- Original Message -
From: Bill Barker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, November 01, 2003 1:00 PM
Subject: Re: Opinions
   

The recent port of the 3.3 variable-substitution to Tomcat 5 may very
 

well
 

solve your problems here :).  The ports are supposed to move to
commons-digester, so should be available in 4.1.30 as well.
Francois JEANMOUGIN [EMAIL PROTECTED] wrote in
message
 

news:[EMAIL PROTECTED]
 

 

Hu! It's in early developments or is it suitable for production ?
 

It's ready for production.  People are already using it in production
with tomcat 5.  Of course, I'm biased ;)
   

Well, there is that beta flag in front of tomcat5 that tell me that your
opinion is more than biased :). Of course, I saw a mail telling that the
beta flag is related to specification instability (not code), anyway...
 

It's a Developer, rather than Sysadmin, option.  Chances are you won't
need to worry about it as you'll use commons-daemon with tomcat, which
already does the required jsvc invocation for you.
   

Well, that does not help that much. I hope that there will be a
configuration scheme that'll let easily define user/group/port and so on
 

for
   

the connectors. Just waiting for a sysadmin point of view :).

Thanks,

François.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
   



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


 



--
http://www.spectacle.ca/
The New Online Source for Live Music in Montreal
.::514.286.1699::.


RE: HOW CAN I USE THREADS IN TOMCAT

2003-11-01 Thread Fred Whipple
I would also add that unless you have a particular need to embed this in
a specific Servlet, it might make more sense to add this thread to a
context listener handler.

For example, if I wanted to send out email to 1000 people (not Spam, of
course! ;-) and I initiated this from within a Servlet, in this case I'd
add a thread to the Servlet and let the Servlet return while the email
was still going out.  This assumes I handle any errors in some other way
than displaying the results on the page.

On the other hand, if I wanted to, perhaps, clean-up some temporary data
within a database every so often, and I wanted to include this
funcitonality within a Web app rather than in a separate application
that I run from the CL via Cron every now and then, I'd probably
implement this within a context listener handler so that the thread
starts up when the Web app starts up and continues utnil the Web app
shuts down.

Just a thought!

-Fred Whipple
 iMagine Internet Services

 -Original Message-
 From: Erik Wright [mailto:[EMAIL PROTECTED] 
 Sent: Saturday, November 01, 2003 11:03 AM
 To: Tomcat Users List
 Subject: Re: HOW CAN I USE THREADS IN TOMCAT
 
 
 A servlet is just a Java class. You can do anything you can 
 do with the 
 java language, including start threads. The following starts a thread 
 that runs some task every 10 minutes. The thread is started in the 
 servlet init method. I choose to set the thread to daemon 
 mode, meaning 
 that when the main thread of execution shuts down the mailer 
 thread will 
 automatically be killed. Otherwise you need to be sure to 
 keep track of 
 it and be sure to signal it to shutdown in your 
 Servlet.destroy method.
 
 public class MyServlet extends HttpServlet
 {
 private static class MailerThread extends Thread
 {
public void run ()
{
   while (true)
   {
   // do something
  synchronized (this)
  {
 wait (10*60*1000);
  }
   }
}
 }
 
 // the servlet init method
 public void init ()
 {
MailerThread thread = new MailerThread ();
thread.setDaemon (true);
thread.start ();
 }
 
 // ... doGet, etc. ...
 }
 
 -Erik


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]