Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:31:09+00:00 2026-06-04T08:31:09+00:00

I have implemented a timer to invoke my alert() method. The duration of the

  • 0

I have implemented a timer to invoke my alert() method. The duration of the timer is retrieved from the database. When I set the duration to 1 minute, the timer invokes alert() every one minute. When I set the duration again for 5 minutes, the 1 minute timer does not stop. So now I have 2 running timers. How can I remove the previous timer? Thanks.

private void getDuration() 
{       
    durationTimer = new javax.swing.Timer(durationDB, new ActionListener() 
    {               
        public void actionPerformed(ActionEvent e) 
        {       
            alert();      
        }     
    });                 
    durationTimer.stop();

    try
    {   
        // Connection to the database
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/smas","root","root");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM alertduration");    

        while (rs.next()) 
        {
            durationDB = rs.getInt("duration");     
        }   

        con.close();            
    }

    catch(Exception ea)
    {
        JOptionPane.showMessageDialog(watchlist, "Please ensure Internet Connectivity ", "Error!", JOptionPane.ERROR_MESSAGE);
    }           


    durationTimer = new javax.swing.Timer(durationDB, new ActionListener() 
    {               
        public void actionPerformed(ActionEvent e) 
        {       
            alert();      
        }     
    });         

    durationTimer.start();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:31:10+00:00Added an answer on June 4, 2026 at 8:31 am

    Call the stop() method when you are finished with the first timer. It may also be worth making your timer global and reusing it rather than creating a new one every time the duration changes. See: http://docs.oracle.com/javase/6/docs/api/javax/swing/Timer.html

    Example:

    durationTimer = new javax.swing.Timer(duration, new ActionListener() {               
        @Override
        public void actionPerformed(ActionEvent e) {       
            alert();
        }     
    });                 
    
    durationTimer.start();
    
    //wait for duration to change
    durationTimer.stop();
    durationTimer.setDelay(duration);
    durationTimer.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a jquery ui autocomplete with data from database. Right now what
I have implemented one application in android which uses epublib to view .epub files.
I have implemented Solr search in one of my .net application. Everything working fine
I have simple drag and drop functions implemented in QmainWindow the reference taken from
I have a method which implements different logic on data fetched from a DB
I have a function that I want to invoke every x seconds, but I
The application uses ADO.NET to invoke sprocs for nearly every database operation. Some of
I have implemented the usual examples of accessing the camera roll on ipad and
I have implemented Twitter4J in my Android application and it's works fine. But after
I have implemented SSO authentication using the sourceforge spnego project . This is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.