Hello everyone,


I want to run tasks with priority, i.e. among several simultaneous running tasks, the task with the higher priority will have more chances to occupy CPU time. I have the following 2 issues dealing with the implementation of such feature.

- To define each task as a thread or as a method? How to change the priority of each task dynamically when they are running?

- 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.

I am wondering whether I can find similar open source projects or tutorials?


Thanks in advance,
George

Thanks server_crash,

You can use threads. Threads allow you to set the priority to affect when it runs in according to other threads.

Here is a small tutorial, don't know if it will help or not.
http://www.dslab.tuwien.ac.at/javatutorial/essential/threads/

Your reply is very helpful! I found that if I use priority feature of Java thread, then I can only have (MAX_PRIORITY - MIN_PRIORITY) different priorities, which may limit my application. I am wondering whether there are any alternate solutions which may have more different priorities.


regards,
George

What is the nature of these tasks you want to run?

In the mean time, Java version 1.5 added a lot of functions for threading. Some of those include: Scheduling tasks, advanced synchronization, and many more. I believe you might find something useful in there. I haven't got a link yet, but I do have a book specifically on 1.5 inwhich I can give you text from.

Thanks server_crash,

What is the nature of these tasks you want to run?

In the mean time, Java version 1.5 added a lot of functions for threading. Some of those include: Scheduling tasks, advanced synchronization, and many more. I believe you might find something useful in there. I haven't got a link yet, but I do have a book specifically on 1.5 inwhich I can give you text from.

Your reply is very helpful! The problem I am meeting with is to develop a simple QoS prototype, in which different tasks can run according to user defined priorities. What things the tasks are doing is not important, and I only care each task can run according to previously defined priority (i.e. the task with a higher priority has more time to run on JVM). Do you have any ideas dealing with how to implement it?

Another issue is that, I am very interested in the book you mentioned. I am wondering whether you have a electronic version of the book to share?


regards,
George

No, I only have the hardcopy version. Here it is on amazon:
http://www.amazon.com/exec/obidos/tg/detail/-/0596007388/qid=1117718725/sr=8-3/ref=pd_csp_3/103-6351424-5749444?v=glance&s=books&n=507846
If you know the name of it, you might be able to find a e-version.

As for helping you, I'm really stuck. Have you tried posting on the java.sun.com forum? That is were all the pros hang out, so if you post there you would probably get a much better reply. If you do decide to do that, let me know what you find out.

Sorry I couldn't help much on this.

Thanks server_crash!

No, I only have the hardcopy version. Here it is on amazon:
http://www.amazon.com/exec/obidos/tg/detail/-/0596007388/qid=1117718725/sr=8-3/ref=pd_csp_3/103-6351424-5749444?v=glance&s=books&n=507846
If you know the name of it, you might be able to find a e-version.

As for helping you, I'm really stuck. Have you tried posting on the java.sun.com forum? That is were all the pros hang out, so if you post there you would probably get a much better reply. If you do decide to do that, let me know what you find out.

Sorry I couldn't help much on this.

Do not say sorry. You are always warmhearted. I have already post my question on java.sun.com, but there are no responses yet. I will let you know if there are any replies in the future.


Have a nice weekend,
George

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.