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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:35:46+00:00 2026-05-17T00:35:46+00:00

I have built a java application and have a thread thats doing something in

  • 0

I have built a java application and have a thread thats doing something in the background when a button was pressed. The problem is, that thread might lock up, perhaps due to an infinite loop. Is there a way I can force terminate that thread?

EDIT: I am using LuaJ on the java platform. It has the potential of locking up and I don’t really have much control over it apart from running it in another thread and killing it when either java or the script is finished.

  • 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-17T00:35:47+00:00Added an answer on May 17, 2026 at 12:35 am

    No, there is not. Your only choice without major witchcraft is to call interrupt() on it and wait for it to hit a blocking call. At that point, it will throw an InterruptedException which you should have terminate the thread.

    If it is in a loop such as while(1); you can’t really do much; you need to fix your thread to not do this, or to at least check a flag and stop itself.

    For example, you could rewrite:

    while(1) {
        doWork();
    }
    

    as:

    class Whatever {
        private volatile boolean stop = false;
        ...
            while (!stop) {
                doALittleWork();
            }
        ...
    }
    

    There used to be a Thread.stop() method that does this but it is deprecated for very, very good reasons and should not be used.

    EDIT:
    Since you’re running presumably an interpreter, what you need to do is hook after every statement is executed (or so) and check your magic stop variable, and if so terminate Lua execution. Alternately, the Lua runtime may have its own “terminate” flag that you can use – I looked for documentation but their site is awful, so you may have to look at the code for this.

    Beyond that, you may have to patch the Lua4j source manually to add this feature. Your options are pretty limited and ultimately the Thread has to somehow control its own fate.

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

Sidebar

Related Questions

I have built a Java application that has some dependencies (~10). I would like
I have built a web application using Java EE platform that sells one of
I'm writing a load-testing application in Java, and have a thread pool that executes
I have an application that is built in Java that requires authorization. However, the
I have a web application, built with Maven, consisting of a Java (Spring) backend
Do Java collections have a built-in method to return multiple items from that collection?
I have an existing system built in Java we currently expand that by adding
I have built an application that I want to use as the foundation for
I have some problem with my java application, I did build it with Eclipse
I have a problem with Hibernate (3.6.0.-Final) in my Java EE application using MySQL

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.