الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

help me in threads and schedulers

مغلق
بدأه mufic_semsem في 18 مايو 2005 · 3 رد · 607 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

iI know that you dont solve problem you just help in them so i have problem and try to solve it

i have a scorce code and the the DR told me to mof\difay it so i will show you the scorce code and the problem and what i do

Copy the files Parent. java, Counter. java, and Scheduler. java to your working directory. Compile and run the program (the Parent class has main()). Look closely at the output. The Scheduler is supposed to set priorities so that only one thread runs during a Scheduler time slice. However, Scheduler is running on top of the Java thread scheduler, so some interesting interactions take place. You'll be asked in lab to identify evidence that Scheduler is not completely in control.

Next, try reducing the size of the DEFAULT_TIME_SLICE constant in the Scheduler. java file (you can also pass in a quantum in Parent. java where the Scheduler constructor is called). Recompile and run the program again, and look at the output. It won't change the interactions, but you should see more frequent Scheduler activity.

Bring to lab the outputs from your original run of the program, as well as the output from a run after you reduce the time slice.

Problems

Here is the basic problem you will address. Imagine writing a Java program which will generate lots of threads. For performance reasons you want to manage the scheduling of these threads yourself - you should remember seeing the code for a Scheduler class from the pre-lab work. You will work with this scheduler to understand how this Scheduler class interacts with the JVM threads scheduler.

The thing that you must keep in mind is that your program (based on the Scheduler class) is run as a thread by the JVM - so to the JVM your program thread, the scheduler thread, and any other threads can all be in the runnable state at the same time. So that if your program's scheduler thinks it has somehow blocked the execution of a thread, that thread is ultimately managed by the JVM - it is really in control. This is why your Scheduler that is defined in the Scheduler. java doesn't have the full control.

Also, remember that the JVM schedules threads using a preemptive priority scheduling scheme.

A.

Modify the Scheduler to include 3 queues representing three different priorities (with values of 2, 3, and 4). The Scheduler should pick a thread from the highest-priority queue that is not empty, and run that thread for a time slice, until all threads in the highest-priority queue are finished. Then move to the next queue, until all queues are empty. Note that in order to implement this, you will have to change the Scheduler so that it sets the priority of the thread it is running to 5, and that it remembers the priority of the running thread so that it can be returned to the correct queue when the time slice is done. Note that you will also have to modify the addThread() method to take a second argument indicating the priority of the thread.

Once you've made the modifications, change Parent. java to start up three counters, one with priority 4, one with priority 3, and one with priority 2. Run the program and verify that it does what you expect.

Hand in the code for the modified Scheduler. java and the output of your test run

لا اله الا الله .......................................... محمد رسول الله

#2

so you know all under stanad that the want is run the first thread by its Priority

tell it finish and then run the next and the next tell the last queue

here it is the scorce code be4 i change in it

OS.zip

لا اله الا الله .......................................... محمد رسول الله

#3

in this is my code i think it is correct but i dont give me the right answer i dont know why

when you run it you will find the it run counter 1 and go to counter 2 or 3 be be4 counter1 end at all

i do some thing but i dont think that it is a good one

that change is not in that code

i do :

in the parent .java i add 2 big for() be4 counter2 .statr and counter 3.start and that to make some time to counter 1 to work

that give me the right answer but in the small time sclices only in the big ones it make as the normal cooode

so plz try to help me ..................

src.zip

لا اله الا الله .......................................... محمد رسول الله

#4

بالعربي الرجاء.........

زورو موقعنا

www.algabal.com

هذا الموضوع مغلق.

مواضيع مشابهة