Java.util.Timer and java.util.TimerTask running threads problem

Hi,
I have following scenario.
1. My thread to send mail has to run at a fixed time interval thus I am using the following method from the Timer class.
scheduleAtFixedRate(TimerTask object, start time, interval)
2. My thread in the class checkDBSendEmail that extends TimerTask class reads database and sends mail based on the data received in the run() method.
3. Whenever I send any mail, I log it into a database table that keeps the record of the emails sent.
4. i have put it some logic to filter data form data base after that it will sends me unique data. Data should be email to different uses based on the list.
Now the Problem:
I am receiving duplicate mails on multiple times.
Is there anything that I am missing in the following that would help me resolve this problem.
my Servlet inti method is:

sorry code is here..........
public class SchduleTimeEmail extends HttpServlet implements SingleThreadModel{
public void init( ServletConfig servletConfig ) throws ServletException{
super.init(servletConfig);
this.config = servletConfig;
try{
// specify in the format as in 12.13.52 or 3:30pm
initialTime = format.parse( config.getInitParameter("initialTime"));
delay = HOURS_24;
RunLogger.addLogger("init first try:"); // log file
catch( ParseException pe ){
// Log.sendMessage( Log.MESSAGE_LEVEL_INFO , "[TimerServlet]", "startTime could not be parsed from web.xml file" );
System.out.println("startTime could not be parsed from web.xml file."+pe);
initialTime = new Date();
delay = HOURS_24;
// Timer Must start combination of 15,30,45,00 min for check schdule
Date dalayTimeMinSec = new Date();
int currentMin = dalayTimeMinSec.getMinutes();
int totalDelayTime = 0;
if(currentMin%15!=0 || currentMin%15 != 15){
try {
int delayMin = currentMin % 15;
totalDelayTime = (15-delayMin) * 1000 * 60;
dalayTimeMinSec.setSeconds(0);
Thread.sleep(totalDelayTime);
RunLogger.addLogger("Thread go for sleep:");
} catch (InterruptedException ex) {
RunLogger.addLogger(ex.toString());
//Start Timer from this time
timer = new Timer();
Calendar time = Calendar.getInstance();
Calendar timeOfDay = Calendar.getInstance();
try{
timeOfDay.setTime(initialTime);
time.set((Calendar.HOUR_OF_DAY), timeOfDay.get(Calendar.HOUR_OF_DAY));
time.set(Calendar.MINUTE, timeOfDay.get(Calendar.MINUTE));
time.set(Calendar.SECOND, timeOfDay.get(Calendar.SECOND));
Calendar startTimeOfTimer = Calendar.getInstance();
startTimeOfTimer.add( Calendar.MINUTE, 0 );
// make sure the first timer doesn't fire before the server starts
if( time.before(startTimeOfTimer) )
time = startTimeOfTimer;
System.out.println("TimerServlet: Timer has been set for " + time.getTime() + " '(" + delay + ")'"); // for checking
checkDBSendEmail msasTask = new checkDBSendEmail();
timer.scheduleAtFixedRate( msasTask, time.getTime(), delay );
catch( Exception e ){
RunLogger.addLogger(e.toString());
public void destroy(){
timer.cancel();
super.destroy();
and another class is:..
public class checkDBSendEmail extends TimerTask{
public void run()
// System.out.println("Function run : "+ functionExcuteCount++);
try{
// DB Logic as well as send e-mail function call
catch( Exception ex ){
RunLogger.addLogger(ex.toString());
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
public String getServletInfo() {
return "Short description";
// </editor-fold>
I also checked the email server settings, and I am sure that the email server is not duplicating the emails.
this code working correctly on my local machine But in live server it duplicating email and still I am receiving duplicate mails.
Any help is appreciated.
Thanks,
Sharda

Similar Messages

  • Java.sql.Date and java.util.Date - class loaded first in the classpath

    I had two jar files which has java.util.Date and java.sql.Date class file. i want to know whether which class is loaded first in the classpath...
    I like to change the order of loading the class at runtime...
    Is there is any way to change the order of loading of class...
    I may have different version of jar files for example xerces,xercesImpl. some of the code uses xerces ,some of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according to the order i need..
    Can we do all these in Run time ?????

    I had two jar files which has java.util.Date and
    java.sql.Date class file. i want to know whether
    which class is loaded first in the classpath...
    I like to change the order of loading the class at
    runtime...
    Is there is any way to change the order of loading of
    class...
    I may have different version of jar files for example
    xerces,xercesImpl. some of the code uses xerces ,some
    of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according
    to the order i need..
    Can we do all these in Run time ?????That is meaningless.
    The classes you are referring to are part of the Java API. Third party jars have no impact on that. And you can't change to the order because java.sql.Data is derived from java.util.Date. So the second must load before the first.
    And if you have two jar files with those classes in them (and not classes that use them) then you either should already know how to use them or you should stop trying to do whatever you are doing because it isn't going to work.

  • Why not Deprecate java.util.Date and java.util.Calendar

    With the introduction of java.time, why did you not flag java.util.Date and java.util.Calendar. These classes have been a bane to every Java developer and should never be used again with the introduction of Java 1.8.

    Adding the @Deprecated annotation would only just provide a warning about an old API and recommendation to the developer(s) to no longer use it. Doing so would not break any existing library out there; in fact quite a number of constructors and methods on the Date class have already been flagged deprecated.
    The new java.time package is far superior to Date/Calendar.

  • Java.util.Map and  java.util.HashMap samples

    Hi.
    Please, I need some code samples of java.util.Map and java.util.HashMap interfaces. I have problems to retreive objects in the map.
    Cheers,
    Cata

    Try the tutorial:
    http://java.sun.com/docs/books/tutorial/collections/index.html

  • Java.util.Date and java.sql.Date

    when i am trying to displaying date in my jsp page errors occurs saying that java.util.date and java.sql.date are matching..
    i have some sql statements which i need to execute in the page.so i cant delete that import sql statement.
    so what is the solution for this.
    i want to display the date as 19th april 2003....in the jsp page.
    thank u

    You should use full names.
    java.util.Date date;
    java.sql.Date sdate;
    ..And it may be a good idea to delete one of the two "import" declaration of packages.

  • Conversions between java.util.Date, java.util.Timestamp and java.sql dates

    I am coding a hoilday booking system using JSP to interact with a SQL Server database. On my JSP form which retrieves the information I have a little javascript pop-up date selector which appears to be returning a Timestamp value although the string value is visable in the entry field. Can I pass this to a javabean as a Timestamp, so far I have only passed strings? Also I then have to enter it in the database and so will need to convert it to an sql date type but I dont know which one is best. Previous to using the Timestamp returning calendar I was just entering text and parsing it to a util.Date in the bean and then converting that to an sql.Date for entry in the database. That worked fine but I want to use the pop-up any ideas? Also my bean won't compile if I declare java.util.Timestamp t;(cannot resolve symbol Timestamp !) even though I have imported util.

    First of all, java.util.Timestamp does not exist. You probably need java.sql.Timestamp.
    java.sql.Date and java.sql.Timestamp inherit from java.util.Date. So converting from java.sql.Date or java.sql.Timestamp to java.util.Date is easy, you don't have to do anything.
    To convert a java.util.Date to a java.sql.Timestamp, do something like this:
    import java.sql.Timestamp;
    import java.util.Date;
    Date date = new Date();
    Timestamp ts = new Timestamp(date.getTime());Jesper

  • Java Web Start and Java Preferences

    I am having trouble with Java Web Start and Java Preferences. I have tried reinstalling the update with the link http://www.apple.com/downloads/macosx/apple/application_updates/javaformacosx105 update6.html but to no avail. What else can be done ? Moreover the file /System/Library/Frameworks/JavaVM.framework/Versions/A/ seems to be in place, but Java Web Start wont open and Java Preferences can't access cache files. Any ideas about how to resolve this? I have been having issues with Java for a long time and have already done a clean Leopard reinstall and all the Combo updates. Java Web Start and Java Preferences worked correctly for a while after that but seem to have gone haywire again.

    bump

  • Lib32-util-linux and lib32-util-linux-ng are in conflict

    hi
    i'm running a 64bit arch linux (with some 32bit apps)
    today i got a strange conflict - and the "solution" seems pretty dangerous to me, or am i wrong?
    [root:~]# pacman -S multilib/dwarffortress
    resolving dependencies...
    looking for inter-conflicts...
    :: lib32-util-linux and lib32-util-linux-ng are in conflict. Remove lib32-util-linux-ng? [y/N] Y
    Remove (1): lib32-util-linux-ng-2.18-3
    Total Removed Size: 0.58 MB
    Targets (41): lib32-libxfixes-4.0.5-3 lib32-libxdamage-1.1.3-3 lib32-pcre-8.10-3 lib32-dbus-core-1.4.0-2 lib32-glib2-2.26.1-2
    lib32-atk-1.32.0-1 lib32-pixman-0.20.2-1 lib32-cairo-1.10.0-3 lib32-pango-1.28.3-1 lib32-util-linux-2.19-1
    lib32-e2fsprogs-1.41.14-2 lib32-openssl-1.0.0.d-1 lib32-db-5.1.19-1 lib32-sqlite3-3.7.4-1 lib32-heimdal-1.3.3-3
    lib32-ncurses-5.7-6 lib32-readline-6.1.002-3 lib32-libgpg-error-1.9-4 lib32-libgcrypt-1.4.6-3 lib32-gnutls-2.10.4-1
    lib32-libtiff-3.9.4-3 lib32-gdk-pixbuf2-2.22.1-1 lib32-libcups-1.4.5-1 lib32-libxcursor-1.1.11-1
    lib32-libxrandr-1.3.1-1 lib32-libxi-1.4.1-1 lib32-libxcomposite-0.4.3-1 lib32-gtk2-2.22.1-2 lib32-libdrm-2.4.23-1
    lib32-libxxf86vm-1.1.1-1 lib32-libgl-7.10.1-1 lib32-mesa-7.10.1-1 lib32-sdl-1.2.14-8 lib32-sdl_image-1.2.10-3
    lib32-flac-1.2.1-7 lib32-libsndfile-1.0.23-2 openal-1.12.854-2 lib32-openal-1.12.854-4 sdl_ttf-2.0.10-1
    lib32-sdl_ttf-2.0.10-3 dwarffortress-0.31.21-1
    Total Download Size: 9.07 MB
    Total Installed Size: 79.96 MB

    ulukay wrote:
    ngoonee wrote:Firstly, searches are not cached, so noone would be able to view your link properly. However yes somehow I've seen that the other threads on this are not turning up, so I suggest instead searching for 'util-linux', not 'lib32-util-linux', you will find the solution then.
    1. thanks for not simply posting a link
    2. that search would return threads regarding this problem on 32bit hosts - i run a 64bit host. my main concern is that this would install incompatible 32bit binaries.
    1. You're welcome. Self-help is the best kind.
    2. If you'd done the search I recommended you would have seen that the problem is not related to arch at all, but is due to upstream renaming.

  • Install Java (1.4) and Java (1.5) on the same Windows XP mc reqd for 2 apps

    I have a requirement to install 2 different versions of Java (1.4) and Java (1.5) on the same Windows XP machine. There are 2 applications one uses Java (1.4) and the other Java (1.5)
    Both the application is run by taking the JAVA Path , Classpath specified in the Environment variables on the Advanced tab in My Computer. How to achieve it ? Immediate help is required. Thanks in advance.

    {color:#ff0000}{size:20px}CROSS POSTED{size}{color}
    [http://forums.sun.com/thread.jspa?threadID=5333227]
    Cross posting is rude.
    db

  • Give me description about JAVA Proxy Runtime and JAVA Proxy Server

    Give me description about JAVA Proxy Runtime and JAVA Proxy Server with some examples.

    Hi,
    Java proxy runtime :
    Using the Java proxy runtime you can receive messages or send messages to the Integration Server.
    This will help you
    http://help.sap.com/saphelp_nw04/helpdata/en/64/7e5e3c754e476ee10000000a11405a/frameset.htm
    Java proxy server :
    The connection to the Integration Server by using the Java proxy runtime.
    This will help you
    http://help.sap.com/saphelp_nw04/helpdata/en/87/5305adc23540b8ac7bce08dbe96bd5/frameset.htm
    Regards
    Agasthuri Doss

  • When I'm on an app, on iso7.1 it will now show the "iPad/iphone" sign the time and the battery whilst running in an app. does anyone know how to get rid of that as its effecting the games i play.

    when I'm on an app, on iso7.1 it will now show the "iPad/iphone" sign - the time - and the battery whilst running in an app. does anyone know how to get rid of that as its effecting the games i play.

    If you can hide the status bar, it would be an option inside the app. I have one or two apps where that is an option but in most apps it is not.

  • HT3275 My Time Capsule has been backing up without any problems and all of a sudden it stops reading on my computer. The external hard drive beeps three times and the motter wont run within. What happened?

    My Time Capsule has been backing up without any problems and all of a sudden it stops reading on my computer. The external hard drive beeps three times and the motter wont run within. The light that usually blinks while in use is no longer blinking and is on constant. What happened?

    abailey46 wrote:
    My Time Capsule has been backing up without any problems and all of a sudden it stops reading on my computer. The external hard drive beeps three times and the motter wont run within. The light that usually blinks while in use is no longer blinking and is on constant. What happened?
    Sorry we are unclear as to the external hard drive and its connection to the TC..
    For instance the light that blinks.. is that the TC or external hard disk or what.
    Did you try just rebooting / restart the whole network in correct order.. modem.. router / TC.. external drive.. clients with 2min gap between each.
    Are you actually running Snow Leopard as the profile states?
    How old is the TC?

  • Differences between Java Virtual Machine and Java HotSpot ??

    I am little bit confused between Java Virtual Machine and Java HotSpot.
    My understanding is:
    Java Virtual Machine is the environment to execute Java programs. I think I could understand this part.
    However, the description says, "The Java HotSpot product line consists of a server-side and a client-side virtual machine that share the Java HotSpot runtime environment, but have different compilers suited to the different performance characteristics of clients and servers."
    I am confused with server-side virtual machine. what is that?? Does it mean the environment to execute Java programs remotely through network?? For example, Java plug-in.?? Please advise.

    Hotspot is a JVM.
    Hotspot has different configuration settings. Some of those settings are better suited for a client application. Some are better suited to server applications.

  • Filepath probs running Java w/ DOS and Java 2 SDK

    Please help! I have been trying to get a .class file to run for the past four days, using DOS to run the file. I have tried to enter every filepath I can -think- of, and the program still will not run. I have even tried running the file on others' computers that also have a Java 2 SDK...and still cannot get the file to run. However, I know for certain that the file is correct and is able to be run....so that means that somehow I am not putting in the right filepath. I guess my question is....what's the file path?
    Here's what I was told to do...which has not worked thus far...
    My Java SDK filepath is: C:/Java2SDK1.4.0
    I was instructed to open DOS, then, to get to here:
    C:\Documents and Settings\Administrator\Desktop>I did so, and as instructed entered the filepath to the javac file inside the java sdk and after it, to put the filename with a .java extension. However, I ONLY have a class file. I don't have the .java file, nor was it ever handed to me.That filepath requested is: C:/Java2SDK1.4.0/bin/javac MathPrac.java
    I entered the filepath, so my DOS prompt looked like this before I hit the enter key:
    C:\Documents and Settings\Administrator\Desktop>C:/Java2SDK1.4.0/bin/javac MathPrac.javaI hit enter, and it gives me a LONG list of garbage. I even tried reversing the slash marks. Please help? This thing is due Monday and my instructor is refusing to return my emails. I don't want to fail this course due to an instructor being unwilling to assist a student, and a student having tried just about everything she could think of before finally coming here and asking for help.
    Would it matter if the SDK for some reason won't recognize my .java files either? I even tried doing the filepath with a file I KNOW should work...and on computers it should have worked on...and could not get it to accept my filepath.
    Any help would be very very very highly appreciated. Thanks!

    Author: philip_ross
    To run a .class file you have to use the java command (javac is the compiler which creates .class files from .java files). Try running
    C:\Java2SDK1.4.0\bin\java MathPrac
    Thank you for the suggestion, however when I attempted to run it, I got an error that said: Exception in thread "main" java.lang.NoClassDefFoundError: MathPrac
    Isn't this an error that states that the name of the file and the class name inside the file are not the same? And if so, how can I check to see if they are the same if I don't have the .java file? I did double-check my spelling, tried it four times just to be sure.
    To ChuckBing:
    Hey, thanks for the tutorial! I'll take a look at that, too. It always helps to have other resources.
    To jwenting:
    <Grin>. Duly noted, and thanks. I was trying to keep from being -too- technical in my explanation of what was going on.

Maybe you are looking for