![]() |
Multithreading on Java
I understand that there's a Task class in C++, but how do I multithread in Java? I can't find any Java counterpart to the C++ class. Thank you
|
Re: Multithreading on Java
|
Re: Multithreading on Java
okay thanks, I didn't think to try that because it's not native to the cRIO
|
Re: Multithreading on Java
The Command Based programming model available through the WPILib is a good way to achieve concurrency in your software.
http://wpilib.screenstepslive.com/s/...ed-programming |
Re: Multithreading on Java
Quote:
Quote:
|
Re: Multithreading on Java
the Scheduler when using command based maintains it's own list of active commands, and (when a DS packet arrives) calls their execute() and isFinished() methods for every command on the list (sequentially).
No preemptive scheduling here, everyone's execute() and isFinished() has to play nice.... |
Re: Multithreading on Java
Quote:
|
Re: Multithreading on Java
Quote:
|
Re: Multithreading on Java
Quote:
Please note: this is not veiled criticism of the command based model; I'm just trying to untangle things. |
Re: Multithreading on Java
Quote:
|
Re: Multithreading on Java
Quote:
Let me try re-wording it:
I have no idea if the above description is an accurate account of what the Command Based implementation actually does, but is that what you meant? Quote:
|
Re: Multithreading on Java
Commands can be running "simultaneously" as long as they don't require writing data to the same Subsystems. CommandGroups are used mainly for automation (ex. I might have a ShootAndReload command group that releases my winch, then proceeds to roll it back up again immediately by calling the different Commands in a certain configuration). You can add Commands to a CommandGroup to run in sequence or parallel.
|
Re: Multithreading on Java
Quote:
Command A requires only Subsystem B and takes 1ms to complete.My question is, how does the CommandBased model implement this, if not by preemptive time-slicing. Posts 6 and 8, and post 10 if I interpreted it correctly, would answer that question. |
Re: Multithreading on Java
They aren't actually running simultaneously. I'm not sure if I'm interpreting "preemptive time slicing" correctly, but any Command-Based program could be written in the IterativeRobot style with a large number of if statements :). They're all running on one thread as I understand it, and I am not sure you have any guarantee to the order they run in. That is why Commands can declare that they require exclusive access to a Subsystem to tell other Commands that they will be writing data to it.
Both commands will run the execute() method in their class each robot loop (usually 20ms) until their isFinished() check (also run each loop) returns true. The Scheduler takes care of all the behind-the-scenes work of maintaining command life-cycles. |
Re: Multithreading on Java
Quote:
initialize execute end interrupted The user provides the code that goes in those methods. There is a fifth method (isFinished()) that allows the scheduler to know when to transition from execute to end. The normal flow is from initialize to execute to end. The scheduler handles interrupting, if a new command is scheduled that requires the same subsystem. A CommandGroup allows multiple commands to be scheduled sequentially or in parallel (being in parallel requires that they don't require the same subsystem). The only times we have had to add an explicit state machine inside a command, is when there is decision logic that needs to go backwards in states. In our case, that's been relatively rare. The scheduler is entirely cooperative. It depends on the commands methods executing quickly and returning. If the user puts an explicit Timer.wait() in a command, it breaks the execution model. The user can either use a WaitCommand, or check a timer in the isFinished method, or implement their own state machine. We've done all 3. |
| All times are GMT -5. The time now is 13:35. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi