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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:21:30+00:00 2026-05-29T11:21:30+00:00

given a Runnable: public class MyRunnable implements Runnable { public void run() { doA();

  • 0

given a Runnable:

 public class MyRunnable implements Runnable {

     public void run() {
        doA();
        for (i=0; i<18123 ; i++) {
            doB();
        }

        doC();
    }
 }

where doA,B,C are defined with like 100 lines of code each.

what is the best way to make the thread FREEZE – in whatever line of code its at – and then continue from the next line of code where it last stopped.

I was searching around the net, and I saw here http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html
that they suggest on using a boolean, so, does that mean that i need to check that boolean after every few lines of code? there’s gotta be a nicer way…

  • 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-29T11:21:31+00:00Added an answer on May 29, 2026 at 11:21 am

    That cannot work in general for the cause Thread.suspend() and Thread.resume() have been deprecated:

    Thread.suspend is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, deadlock results. Such deadlocks typically manifest themselves as “frozen” processes.

    If you absolutely need this behavior, you have to explicitly implemented it yourself.

    The implementations could look like this (code not tested, nor compiled):

    public abstract class SafeStoppableRunnable implements Runnable {
        private boolean stopped = false;
    
        public synchronized void stopSafe() {
            this.stopped = true;
        }
    
        public synchronized void resumeSafe() {
            this.stopped = false;
            synchronized(this) {
                this.notifyAll();
            }
        }
    
        protected synchronized void waitWhenStopped() {
            while(this.stopped) {
                this.wait();
            }
        }
    }
    

    The stoppable Runnables should then extend SafeStoppableRunnable and call the method waitWhenStopped() at all the points in your program you want it to be stoppable. Stoppable points are probably points where the program does not hold global ressources other threads need to make progress.

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

Sidebar

Related Questions

Given this code: public class Messager implements Runnable { public static void main(String[] args)
public class PingPong implements Runnable { synchronized void hit(long n) { for (int i
Consider the following code :- public class UsingWait1{ public static void main(String... aaa){ CalculateSeries
Given the following code: public class FooBar { public static volatile ConcurrentHashMap myConfigData =
I wrote a Multithreaded program in Java given below :- public class Client {
I have this class: public class Test { public static void main(String[] args) {
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
I built a runnable JAR from an Eclipse project that processes a given XML

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.