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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:25:06+00:00 2026-05-27T03:25:06+00:00

I need to have a thread which checks for network connection availability on a

  • 0

I need to have a thread which checks for network connection availability on a JAVA desktop app. I got a thread like this

    class DataSyncThread extends Thread {
     DataSyncThread() {
     }

     public void run() {
         while(true){
            try{
                System.out.println("Checking for network");
                InetAddress addr = InetAddress.getByName(host);
                if(addr.isReachable(MIN_PRIORITY)){
                    syncData();
                }
                this.sleep(1000000);
            }catch(Exception e){}
         }
     }
 }

Now when I call this in the constructer the app never loads. when I look into the console (I trigger the jar to load from it) the thread work, it prints “Checking for network” in the console.

help appreciated

  • 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-05-27T03:25:07+00:00Added an answer on May 27, 2026 at 3:25 am

    My guess is that you’re doing something like:

    DataSyncThread thread = new DataSyncThread();
    thread.run();
    

    That will run the run() method synchronously. You should be calling start() to create a separate thread of execution:

    DataSyncThread thread = new DataSyncThread();
    thread.start();
    

    I would also recommend implementing Runnable instead of extending Thread – or quite possibly using a Timer instead, given that you want periodic execution. I hope your real code has logging in your catch block, too…

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

Sidebar

Related Questions

I have an activity which checks username availability via .net web services, I need
I have written a class that checks a POP3 account and I'd like it
I have a thread in Java which starts a HttpService . ProcessBuilder pb =
I need in wpf app check messages on server. I have own method which
I have a web app which displays a list of emails that need to
I need to have a thread signal another if the user wishes to interrupt
I am using ACE threads and need each thread to have its own int
I have a Queue object that I need to ensure is thread-safe. Would it
I need to kill specific worker thread in my application. I don't have any
I need to make an ArrayList of ArrayLists thread safe. I also cannot have

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.