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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:42:49+00:00 2026-05-26T21:42:49+00:00

Why is starting a new thread in a constructor frowned upon in Java (or

  • 0

Why is starting a new thread in a constructor frowned upon in Java (or anywhere, for that matter). I’m getting warnings from Netbeans for doing so, but it isn’t giving me any refactoring suggestions. I’m writing a client/server Swing application, and the thread I’m starting is in the server’s JFrame constructor, in order to continuously listen for client datagrams.

Why is this not good practice and how should I avoid it?

  • 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-26T21:42:49+00:00Added an answer on May 26, 2026 at 9:42 pm

    Starting a thread from the constructor lets the started thread access the object being constructed before it’s properly constructed, and thus makes a not completely constructed object available to the new thread.

    You could create the thread in the constructor, and provide a “startup” method to start the thread from the outside.

    Or you could make the constructor and startup methods private and provide a static factory method which would create the object, start the thread, and return the created object.

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

Sidebar

Related Questions

Starting a new thread... about same question.. I have tried all I am getting
When I'm creating a simple Windows form, is it starting in a new thread
Can I avoid third party code from creating new threads, starting new VMs, or
When starting a new project that required the use of membership providers I found
I found information from this thread and am starting to wonder if the information
What is the difference between: Starting a new thread Using TPL Using BackgroundWorker All
NanoHttpd server code can be found here . I'm starting a new Thread in
apologies for having to create a new thread for this but I'm starting out
In my android service, I'm starting a new thread like this thread = new
I have a gui thread starting a new thread to do some busy things.

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.