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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:01:57+00:00 2026-05-24T00:01:57+00:00

I have the following Groovy code: abstract class Actor extends Script { synchronized void

  • 0

I have the following Groovy code:

abstract class Actor extends Script {
    synchronized void proceed() {
        this.notify()
    }

    synchronized void pause() {
        wait()
    }
}

class MyActor extends Actor {
    def run() {
        println "hi"
        pause()
        println "hi again"
    }
}

def theactor = new MyActor()
theactor.run()
theactor.proceed()

When I run the code, I want the code to output “hi” and “hi again”. Instead, it just stops at “hi” and gets stuck on the pause() function. Any idea on how I could continue the program?

  • 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-24T00:01:58+00:00Added an answer on May 24, 2026 at 12:01 am

    As Brian says, multithreading and concurrency is a huge area, and it is easier to get it wrong, than it is to get it right…

    To get your code working, you’d need to have something like this:

    abstract class Actor implements Runnable {
      synchronized void proceed() { notify() }
      synchronized void pause()   { wait()   }
    }
    
    class MyActor extends Actor {
      void run() {
        println "hi"
        pause()
        println "hi again"
      }
    }
    
    
    def theactor = new MyActor()             // Create an instance of MyActor
    def actorThread = new Thread( theactor ) // Create a Thread to run this instance in
    actorThread.start()                      // Thread.start() will call MyActor.run()
    Thread.sleep( 500 )                      // Make the main thread go to sleep for some time so we know the actor class is waiting
    theactor.proceed()                       // Then call proceed on the actor
    actorThread.join()                       // Wait for the thread containing theactor to terminate
    

    However, if you are using Groovy, I would seriously consider using a framework like Gpars which brings concurrency to Groovy and is written by people who really know their stuff. I can’t think of anything that llows this sort of arbitrary pausing of code however… Maybe you could design your code to fit one of their usage patterns instead?

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

Sidebar

Related Questions

I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue
I have following classes. class A { public: void fun(); } class B: public
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have the following code: InputStream reportFile = MyPage.this.getClass().getResourceAsStream(test.jrxml); HashMap<String, String> parameters = new
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have a groovy class that has the ability to write its output to
Lets assume that I have the following configuration in my conf/InjectionConfig.groovy file: x {
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

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.