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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:54:34+00:00 2026-05-23T13:54:34+00:00

I Want to execute a Certain Task to take only 1000 MS , if

  • 0

I Want to execute a Certain Task to take only 1000 MS , if it exceeds , i dont want to continue with the task ,
i have used join for this .

Please tell me and guide me if this is correct or not

import java.util.List;

public class MainThread {

    public static void main(String args[]) throws InterruptedException {
        Thread mainthread = Thread.currentThread();
        ChildThread child = new ChildThread();
        Thread childThread = new Thread(child);
        childThread.start();

        mainthread.join(1000);
        List list = child.getData();

        if(list.size()<0)

        {
            System.out.println("No Data Found");
        }
    }
}

ChildTHread

import java.util.ArrayList;
import java.util.List;

public class ChildThread implements Runnable

{

    List list = new ArrayList();

    public List getData() {
        return list;
    }

    public void run() {
        // This List Data is feteched from Database currently i used some static data
        list.add("one");
        list.add("one2");
        list.add("one3");

    }
}
  • 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-23T13:54:35+00:00Added an answer on May 23, 2026 at 1:54 pm

    Nope. Incorrect. You do not need MainThread at all, you should call childThread.join(1000) instead.

    But there is a problem with this approach as well – it will mean that the child thread will anyhow continue to be running.
    Therefore you should call also childThread.interrupt() after join:

    childThread.join(1000);
    childThread.interrupt();
    

    and in your child thread periodically in your childThread perform something like that:

    if (interrupted()) {
       return;
    }
    

    and handle InterruptedException where needed – usually around any wait() methods you have.

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

Sidebar

Related Questions

I have a command that I want to restrict only to certain ranks. I'm
I have an if statement that I want to execute if a certain variable
I have a certain oracle package file (pbk with pks). I want to execute
I have a situation where I want certain code to be executed no matter
I want to execute this script (view source) that uses Google Translate AJAX API
I have a custom component which extends LinearLayout, I need to execute certain statements
I want to do a certain task if i hold and press the UIButton
I have an ArrayList of type String that contain certain values. I want to
I want to execute a static method from certain class in certain namespace, but
I'm working this programming task for college where we have to write a c++

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.