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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:46:36+00:00 2026-05-15T10:46:36+00:00

This question is related to How to Queue and Call Actual Methods.. . Anyway,

  • 0

This question is related to How to Queue and Call Actual Methods... Anyway, I’ve decided to (after all) go with the anonymous class idea. The problem is that when I ADD my anonymous class to the linked list, it’s actually calling execute() immediately… and it shouldn’t be. Execute() is to be called later. Anyway, this is what I have:

private LinkedList<AgentAction> actions;
public boolean blockingSensor;

this.actions.add( new AgentAction(this) {
 public void execute() {
  //setRotationalVelocity(0);
  kinematic.setWheelsVelocity(0,0);
  this.agent.setBlockingSensors(false);
  this.agent.printLCD("Turn, blocking = "+this.agent.blockingSensor);
 }

 public Object getValue() {
  return null;
 }
});

//this is essentially the main()
public void performBehavior()
{
    //make sure to only call run() each tick, not every ms
    if ( this.oldCounter < getCounter() )
    {
        if ( !isWorking() )
        {
            run();
        }
        this.oldCounter = getCounter();
        this.actions.removeFirst().execute();
    }
}

abstract class AgentAction
{
 SimbadAgent agent;
 public AgentAction(SimbadAgent a)
 {
  this.agent = a;
 }
 public abstract void execute();
 public abstract Object getValue();
}

run() is an abstract method that is implemented by a child class. I’m just not sure why it’s printing when it’s added, rather than executed. I understand this would imply that performBehavior() is actually being executed multiple times rather than once per tick, but that’s not the case.

  • 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-15T10:46:37+00:00Added an answer on May 15, 2026 at 10:46 am

    The devil is in the details. There’s almost certainly a bug somewhere in the code you’re not showing (my guess is run), but let’s address a deeper point. This code looks a LOT like there producer-consumer problem. If so, I recommend checking out java.util.concurrent: it’s overflowing with concurrency-related goodness that makes things like this WAY easier than trying to roll your own. For your particular case, it looks like ScheduledExecutorService might be a good fit. If it’s not exactly what you need, I still recommend poking around in the package; like I said, it’s stuffed with handy things that will probably be a lot easier to work with than something you built yourself from the concurrency primitives.

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

Sidebar

Related Questions

This question is related to extending class methods in Ruby, perhaps more specifically in
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question is related to the one I asked here . I'm trying to
This question is related to another question, where I wanted to define a custom
This question is related to my previous post Image Processing Algorithm in Matlab in
This question is related to this SO post Rather than using a recursive CTE
This question is related to awk, I suppose. I have no experience with awk.
This question is related to another question of mine. Thanks to some help I
This question is related to database/RDBMS where i have little knowledge regarding performance and

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.