Originally posted by Stuart Gray:
I doubt you can do this since these precise aspects of the JVMs operation are not defined by the specification.
Originally posted by Stuart Gray:
No, I think it is still dependant on the implementation of the JVM. There is no to guarantee a specific priority or order of execution AFAIK.
Originally posted by George Lin:
Thanks Stuart,
Your reply is very helpful to guide me to make the decision, i.e. whether I will use Java to implement this feature. I want to know whether your opinions are Java is not suitable for this feature.
regards,
George
Originally posted by John Smith:
-How to change the priority of each task dynamically when they are running?
You may want to experiment with the setPriority() method to see what it does. Here is an example:
- The priority feature of Java thread does not meet my requirement, since I can not define priority precisely. For example, I want to define that a task with priority A will occupy CPU time 3 times than a task with priority B.
Does the CPU time need to be sliced precisely? If you could live with just minimum and maximum priorities, the threading model may work for you. Otherwise, perhaps you need to consider some other solution. What's the problem you are trying to address?
Originally posted by Henry Wong:
The reason that the Java specification does not strictly enforce how the priority will affect the timeslice of the thread is because most JVMs are written to use the underlying threading model.
However, the threading model on Windows will try to give more time to a higher priority thread, while making sure that the low priority thread do not starve. So if you are using Java on Windows, it will behave somewhat close to what you want. (Be warned, there are many other factors that affect what happens to a thread)
Henry
Originally posted by Stuart Gray:
As Henry confirms, I think 'try' is the closest you are going to get when it comes to thread management.
Question: Will the thread management vary even across different versions of Windows (I would imagine so, at least because 9x only supports single processors, while the NT kernel supports multiple processors).
Originally posted by John Smith:
Let me throw you something alternative to you: how about giving up on threads and priorities, and making use of a priority queue which contains the tasks to be executed in a sequence? That way, you can rearrange the tasks dynamically, at any time, in a very precise fashion, your code will be portable, and the results will be predictable.
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|