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 8143213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:03:57+00:00 2026-06-06T13:03:57+00:00

I have a swing application that uses some datas coming from an external mysql

  • 0

I have a swing application that uses some datas coming from an external mysql database.

I want these datas to be up to date, so i have a thread that check each 10seconds if new datas are available.

here’s my code :

public void run() {
    maj.getIgor().open(); // open the connection to Mysql
    while (true) {
        try {
            if (maj.getIgor().getConnexion().isValid(2)) {
                maj.checkProduits(); // update the datas
            } else {
                maj.getIgor().close();
                maj.getIgor().open();
                System.out.println("Re-try to open connection");

            }
            ThreadIgor.sleep(10000);

        } catch (SQLException ex) {
            Logger.getLogger(ThreadMajProduits.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            try {
                Thread.currentThread().interrupt();
                maj.getIgor().close();

            } catch (SQLException ex1) {
                Logger.getLogger(ThreadMajProduits.class.getName()).log(Level.SEVERE, null, ex1);
            }

            break;

        }
    }
}

I was wondering if that’s a correct way to do what i want and if there’s no risks this thread blocks my application by trying to connect to the db?

Thanks

  • 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-06T13:03:59+00:00Added an answer on June 6, 2026 at 1:03 pm

    First off, as soon as you’re using a connection pool to get connections to your DB, you shouldn’t have a problem with your thread causing any delays to your app. If you’re not using a connection pool, you will eventually introduce pauses in your main app threads, or even race conditions, if you’re not synchronizing your threads correctly.

    A thought that crossed my mind when reading your question is the following, read on if interested, ignore if I guessed wrong!

    What you’re doing essentially is polling the DB for “new” data. The problem is, even if you do get newer data in one of these polls, you will not have made it any safer that the next transaction your user performs will not be based on stale data. This is a fundamental concurrency problem and no matter what “tricks” you do, you cannot get away from dealing with it inside your transactions.

    If what you’re trying to accomplish is to dynamically update the data of some form your user is manipulating, the correct thing to do is to use something like a “last-update” or “version” column. Then, when your user tries to push their updates to the DB, inside your transaction, you will be checking that the “last-update” or “version” of the data your user has been editing is indeed the same with the data in the DB, thus ensuring no one else has edited the same data in the meantime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented an Java Swing application that uses an embedded JavaDB database. The
I have a Swing application that uses a Java Thread to constantly perform some
I have a Swing application that I would like to convert from spaghetti to
I have a stand-alone, Swing application that uses Hibernate for its persistence layer. I
I have a small Java Swing application that I want to rewrite in WPF
I have a Java Swing application client that I want to use to consume
I have an application that uses Swing. The display I am working on, uses
I am working on an application that uses Swing. I have a JTabbedPane, and
I have a (Swing + AWT) application which uses an external jar library (by
I want to create an application that uses a shipping calculator on an external

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.