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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:44+00:00 2026-05-23T10:53:44+00:00

I have a requirement, that I want to start a poller once which will

  • 0

I have a requirement, that I want to start a poller once which will run foreever until the machine is restarted or the process is being killed. Now, I tried to start the poller from a main method using a shell script, but the problem is that as soon as the main method completed its execution, the poller also stoped working, as i am not using any servers to achieve so.

I heard something about daemon threads, but I am wondering how to create a daemon thread, which will run forever, and help my poller to run also.

UPDATE:

public class SomeThread extends Thread {

    @Override
    public void run() {
        UnitPoller unitPoller = new UnitPoller();
        unitPoller.doPolling();
    }

    public static void main(String[] args) {
        SomeThread someThread = new SomeThread();
        someThread.setDaemon(true);
        someThread.start();
    }
}

Above is my updated class, now whenever I execute this thread from the main method, it creates a thread but as soon as the execution of main method completes, my poller stops working, as the JVM shuts down.

With this problem, what should i do.

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-05-23T10:53:44+00:00Added an answer on May 23, 2026 at 10:53 am

    You just create a thread and call th.setDaemon(true) before calling th.start().

    Edit:

    The above answers the question “how to create a daemon thread”, but (as the scope of the question has changed), a proper answer would be: don’t create a daemon thread if you want your thread to keep the JVM from exiting once the main thread completed.

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

Sidebar

Related Questions

I have a requirement that I want to check the request headers and according
I have a requirement that i want to get all the system services running
My requirement is that I want an object (tee) to update if there have
We have legacy applications which soon they will start to use common jsp pages.
I have one requirement that I want to create a pool of 5 threads
I have functlion which is working perfactly. Now the client’s requirement is that he
In our project we have requirement that, after receiving sms message from third party
I have the requirement that I need to open a document in Microsoft word
I have a requirement that I need to show my records in a gridview
I have a requirement that when the user clicks on [X] button of the

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.