• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Servlet sending an email

 
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written two java programs which actually do the following:
1)Connect to one CRM Server.(using server API)
2)Get the Server statistics data.
3)Write this data to a log file
The above tasks are being excuted by another class using Timer and TimerTask with regular interval of 30 minutes.Now instead of reading a log file from a server,people want that log file to be posted on their email addresses. I think Java Mail API can be used.But I am thinking use of Servlet might be better as I can create HTML file containing server statistics and then send it to people.
Do you have any better suggestion?
(Instead of using Timer/TimerTask,we can also use quartzscheduler, open source java schdeular, similar to cron scheduling but this will be at later stage.]
In short my question is : Is it possible to write scheduler which will run the servlet every 30 minutes which in turn will use above classes,get the statistics data and using mail API,post the contents to clients?
[ January 26, 2005: Message edited by: Arjun Shastry ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTTPServlets respond to HTTP requests. In order to "run" a servlet you need a request for it to respond to. For that reason its not a good fit for a timer style service, and a plain old Timer is better. You are already persisting your data toa file - so I'd write a Timer & TimerTask to read the file and mail it with the JavaMail API and forget about using a servlet.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can in fact launch a servlet on server startup.
If you then create a Thread in the init method which responds to timer events that will do the trick.

Unless there's a good reason to do something like this it's not generally the best way to go though (one reason could be periodic clearing of a cache used by the servlet).
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeroen Wenting:
one reason could be periodic clearing of a cache used by the servlet).



Hi Jearon,

What do you mean by clearing the cache?.Do you mean reducing the memmory heap used by JVM?,using System.gc()?.Or any other methods for it?.

Thanks
MM
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what ContextListeners were designed for.
 
Arjun Shastry
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.I am not using Servlets causing unncessary burden.As said I am TimerTask,Mail API and sending mail through SMTP Server.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murasoli Maran:


Hi Jearon,

What do you mean by clearing the cache?.Do you mean reducing the memmory heap used by JVM?,using System.gc()?.Or any other methods for it?.

Thanks
MM



No.
Consider the following (realworld) scenario:

We have a group of servlets that require access to a list of records from a database table.
The content of this table changes rarely but it can change.
What I've implemented is a class to hold the information from a single record.
This class can also read a full list of this table and store it as an ArrayList.
The servlet which is used to maintain the content of the table (through a JSP front end) launches a thread which clears the list every hour (it also rebuilds the list whenever it writes to the database) to take into account the remote possibility that the data changes through some other means (at the moment the application that was originally used to control the data is still available to users but will be used less and less as time goes on).

All this thread does is null every element in the list and then the list itself.
 
Murasoli Maran
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good info Jearon,

I have used it when i was doing an Axis program.The client invoke the server and store all the details to populate the UI(Mostly items for listboxes)in a temporary cache class.So client need not call server for all the time.Cache will be enough.

But i suggest to add a system.gc() aslo in the scheduled task(crontab),If there is any.

MM
[ January 28, 2005: Message edited by: Murasoli Maran ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic