1

I am thinking how to build a real-time system using java without Sun Real-time System API.

Say, a boss generates an event at 11:00 am, he has to get feedback at 11:10 am. If no any feedback, he will resend his event.

The staff gets his boss's event at 11:01 am, he has to leave 1 minutes for sending his result back to his boss. So actually he has 8 minutes to do his job. At 11:09 am, he has to send a feedback no matter he finished it or not.

This is a real-time system, isn't it ?

In this case, how to design our system using java ? This is a producer-consumer pattern. In the consumer side, use which object (blockingqueue, delayqueue ...) to meet this requirement ?

Any weblink, open source will be welcome.

Thank.

andersoj
  • 22,406
  • 7
  • 62
  • 73
user534009
  • 1,419
  • 4
  • 23
  • 25
  • 1
    Is this really a description of the problem or just a metaphor? – thejh Dec 15 '10 at 17:12
  • 1
    You also need to expand on how real-time it needs to be. There is a difference between hard real-time and soft real-time. For example, a car braking system is hard real-time (catastrophic if response time is too slow), whereas a cell phone transmission might be soft real-time (degraded quality, but not catastrophic). Also, real time just means operating in a guaranteed set of time constraints. Does your system actually need to be real time, or just close to on schedule (it may be off by a few milliseconds for example)? – Jeff Storey Dec 15 '10 at 17:28
  • 2
    Does the boss care whether the feedback is exactly at 11:00:00 and not a microsecond after *or before*? If yes, then it's real-time, and you can't afford the non-deterministic behavior of a JVM. If a response anytime between the initial email and 11:00:59 is acceptable, then it's not real-time. – Anon Dec 15 '10 at 17:30
  • Boss has to know the result no later than 11:10 am. If it is before 11:10 am , why it is NOT a real-time system ? – user534009 Dec 15 '10 at 18:57
  • Java (without RTS) is totally incapable of making a hard guarantee that anything will ever happen at or before a specific point in time. We can make safe assumptions based on the knowledge that the underlying platform is well designed and behaves fairly, but that's different from claiming the system is actually Real-Time the way say, the computer that makes sure the robot arm is ready to bolt on a wheel when the car chassis rolls by on the assembly line is real time. – Affe Dec 15 '10 at 19:08

2 Answers2

3

You cannot do real-time programming in the real computer engineering sense in Java. You are at the mercy of a thread scheduler and an operating system with totally unknown underlying properties. If the OS felt like waiting until 11:20 until it got back around to giving the JVM some CPU time, that's its business.

If you mean "realtime" in the Microsofty way as in "Things respond really really fast and we're careful never to block the main UI thread" that doesn't have a well defined technical meaning. It just means "architecture user facing code to give the appearance they don't have to wait on the computer."

--edit in response to comment.

If by 11:08 you mean 'between 11:07:59 and 11:08:01' then regular java can generally do that for you on a modern platform with careful programming. What it can't deliver is a situation where the event happening at 11:08:01 is considered a platform defect, it just doesn't make that guarantee.

When we say 'real time' and what the RTS API is for, is a situation more like "The bonding head must be at these coordinates at exactly this millisecond, if it's more than half a millisecond late, the part will be defective, and if it's more than 2 milliseconds early, a $300,000 servo table is going to crash into its bearings and cause a $10,000,000 assembly line outage."

Affe
  • 47,174
  • 11
  • 83
  • 83
  • In my mind, real-time just means that it will definitely get response in a predefined time period. And also, JVM pause time can be tuned. – user534009 Dec 15 '10 at 19:08
  • In your definition, I will doubt that even RTS API can't achieve it. C++ can do this ? – user534009 Dec 15 '10 at 20:25
  • it depends on the underlying platform, not the particular programming language. C++ on an RTOS can, sure. Do note that Java RTS is only supported on a handful of very specific operating systems. Yes my example was extreme and would certainly be implemented in something like C or even the micro controller's native assembler, the point was to illustrate the engineering meaning of 'real time', which is what the RTS API is meant to add to Java. – Affe Dec 15 '10 at 20:31
0

The system you described can be solved with JMS.

Use a pub-sub JMS queue to assign the work. The "boss" is the publisher. Each member of the staff is a "subscriber".

The "boss" will need to store each message it publishes in a "check back" area (perhaps a list) and set a timer for 10 minutes. When it gets a response to a message, it will clear the timer and remove the message from the "check back" area.

DwB
  • 37,124
  • 11
  • 56
  • 82
  • JMS system is non-deterministic. And performance is not good. In my mind, Socket will be better. Client will scan the server in a certain time period, and send the result back to Boss using socket. – user534009 Dec 15 '10 at 19:03