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

The Archive Base Latest Questions

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

I am working a much more complex version of this (with vehicle moving in

  • 0

I am working a much more complex version of this (with vehicle moving in both X and Y directions)

I made this example to get ideas on better ways to accomplish this.

  1. I have a vehicle moving in the X direction at a speed (24.5872 mps)
  2. I am simulating this by incrementing the X value every 100 ms using an executor (To keep its X position more accurate and real time)
  3. After each second, I send a message to another process with the xMin and xMax values of the line I just covered
  4. The other process will respond with a JMS message (usually instantly) telling me to stop if there was an “Pothole” in the previous X area (Message callback msg to a linkedblockingqueue).

The problem I have is with the “usually instantly” part. If I do not get a response quick enough, I think it will throw off the whole timing of my algorithm. What is a better way to handle this situation?

Here is some basic code of what I am trying to do:

public class Mover implements MessageHandler {

    private static final long CAR_UPDATE_RATE_IN_MS = 100;
    private static double currX = 0;
    private static double CONSTANT_SPEED_IN_MPS = 24.5872; // 55 mph
    private static double increment = CONSTANT_SPEED_IN_MPS / (1000 / CAR_UPDATE_RATE_IN_MS);
    static LinkedBlockingQueue<BaseMessage> messageQueue = new LinkedBlockingQueue<BaseMessage>(); // ms

    private static int incrementor = 0;

    public static void main(String[] args) {
        startMoverExecutor();
    }

    private static void startMoverExecutor() {

        ScheduledExecutorService mover = Executors.newSingleThreadScheduledExecutor();
        mover.scheduleAtFixedRate((new Runnable() {

            @Override
            public void run() {
                currX = incrementor * increment;

                if (incrementor % (1000 / CAR_UPDATE_RATE_IN_MS) == 0) {
                    System.out.println(currX);

                    sendMessage(currX - CONSTANT_SPEED_IN_MPS, currX);

                    // do something
                    try {
                        messageQueue.poll(1000, TimeUnit.MILLISECONDS);

                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
                incrementor++;
            }

        }), 0, CAR_UPDATE_RATE_IN_MS, TimeUnit.MILLISECONDS);

    }

    @Override
    public void handleMessage(BaseMessage msg) {
        messageQueue.add(msg);

    }

    protected static void sendMessage(double firstX, double secondX) {
        // sendMessage here

    }

}
  • 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-14T00:57:44+00:00Added an answer on May 14, 2026 at 12:57 am

    I am proposing changes to your algorithm above as shown in steps below.

    JMS Call to other process


    1a. Start with sending the current position of vehical.

    1b. The other process will respond with a JMS message containing list of all the “Pot holes positions” in the visible area of your vehical’s position. Keep this list of “visible pot holes positions” at client side for use in steps below.

    1c. We define visible area as vehical’s neighbouring area such that even with (1-second-delay + network-lag) of calling other process with JMS, movement of vehical should not cross this area.

    1d. After each second, repeat steps 1a and 1b and replace list of pot holes positions at client side relative to current position of your vehical.

    .

    Vehical movement observer


    2a. Implement an Observer pattern which can receive notifications of vehical movements.

    2b. Each time event is generated, observer will make a check if vehical’s position matches with one of the entry in list of visible pot holes acquired in step 1b.

    2c. If match found, bingo! You got to stop the vehical.

    .

    Vehical movement


    3a. Register step-2a observer to observe vehical’s movements

    3b. Wait until you have got atleast first list of visible pot holes from step 1b.

    3c. Start moving the vehical by incrementing the X value every 100 ms. Each time it moves, it should notify the step-2a observer.

    .

    Legends for below diagram:


    o - Instance of each pot hole somewhere on map 
    X - Moving vehical
    . - Path followed by vehical
    Circle - Visible area of the vehical driver
    
    +---------------------------------------------+
    |                                             |
    |                    o                o       |
    |    o                                        |
    |                                             |
    |                                             |
    |                _.-''''`-._                  |
    |    o         ,'           `.             o  |
    |            ,'  o            `.              |
    |           .'    .            `.             |
    |           |      . .          |             |
    |           |         .         |   o         |
    |           |         X         |             |
    |   o       \                o  /             |
    |            \                 /              |
    |             `.             ,'               |
    |               `-._     _.-'                 |
    |                   `''''                     |
    |                                             |
    |                  o                          |
    |                                    o        |
    |                                             |
    |                                             |
    |     o                        o              |
    +---------------------------------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is realated to a much more complex earlier post , where I was
i'm working on a project which works very much with ajax (made via jquery).
I've been working at this for two days and have not had much luck.
I'm working on a project that is using jQuery, which I'm much more familiar
I don't have much experience working with resultsets, but as ResultSet is an interface,
How much does the garbage collector affect performance when working with lots of objects
Working with a WPF application. I am very much wonderin if it is possible
I'm working on an ASP.NET and someone asked me how much time it would
I'm working on an iPhone application and trying to conform to MVC as much
When I started working on my project I didn't really care so much about

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.