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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:50:30+00:00 2026-05-30T03:50:30+00:00

I was wondering do we require external synchronization to use the methods in java.lang.Thread

  • 0

I was wondering do we require external synchronization to use the methods in java.lang.Thread?

For example, can we call the method t1.isAlive() from any thread without external synchronization and expect that it return:

true if t1 has already been started, false otherwise.

Or is external synchronization required to call the methods in java.lang.Thread?

public static void main(String args[]) {
        final java.lang.Thread t1 = new java.lang.Thread(new java.lang.Runnable() {

            @Override
            public void run() {
                while(true){
                    //task
                }
            }
        });
        java.lang.Thread t2 = new java.lang.Thread(new java.lang.Runnable() {

            @Override
            public void run() {
                while (true) {
                    System.out.println(t1.isAlive()); // do we need synchronization before calling isAlive() ?
                }
            }
        });
        t2.start();
        t1.start();
        try {
            java.lang.Thread.sleep(1000000);
        } catch (java.lang.InterruptedException e) {
            e.printStackTrace();
        }
    }
  • 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-30T03:50:32+00:00Added an answer on May 30, 2026 at 3:50 am

    Yes it should already be thread safe. You can look at the source code of Thread.java here all the important methods such as start etc are synchronized.

    The is_Alive is a native method implemented in a lower layer so will give an instantaneous answer as to whether the thread is started or not, it is not synchronized so it may give a false right after the start method is called. Although this is very very rare.

    The start method does however check the threadStatus member variable before proceeding with its operation and this is a volatile int i.e. will be instantly updated across all accessing threads. So you can use the getState call to check whether a thread is started rather than the isAlive method to avoid the calling start twice. I have copyied the relevant parts of Thread.java below.

    /* Java thread status for tools,
     * initialized to indicate thread 'not yet started'
     */
    
    private volatile int threadStatus = 0;
    
    ...
    
    public synchronized void start() {
        /**
         * This method is not invoked for the main method thread or "system"
         * group threads created/set up by the VM. Any new functionality added
         * to this method in the future may have to also be added to the VM.
         *
         * A zero status value corresponds to state "NEW".
         */
        if (threadStatus != 0)
            throw new IllegalThreadStateException();
    ....
    
    public State getState() {
        // get current thread state
        return sun.misc.VM.toThreadState(threadStatus);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there was anyway to use functions like ReadFileEx that require
I'm wondering why calls to operator methods don't require a dot? Or rather, why
I tend to use external JAXB bindings files for my Schema-to-Java compilation. This works
I'm wondering if there is any desktop OLAP solution that can use SQL Express
i'm wondering how does the media servers work, do they require large bandwidth if
Wondering if anyone has gotten the infamous database is locked error from Trac and
Wondering if anyone can help me with this annoying but trivial (in terms of
just wondering if there is a simple way in java to display the contents
I was wondering if using require() in node.js was the equivalent to lazy loading?
I'm developing an app that will require setting and removing alarms accordingly. I'm wondering

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.