[ July 20, 2006: Message edited by: Stan James ]
by time I mean, job 4 gets put into the priority queue at 2 min..
and has 138 pages...
and according to what priority the job has depends on where it gets placed..
because we're implementing a queue using doubly linked lists...
their are 4 priorities....
and if you insert a job with any priority less than "priority" then you
have to insert a boost behind it, with time 30min, so that if it has not printed in 30 mins, you changes its priority to higher.
well 30min if its development, 25 if its client, and 20 if its system..
but there is also a main timer that goes to 100 min. so it can simulate page printing, then quits...
where p = priority, S = system, C = client, D = development;
and say you boost the C, which has to be the C right after S, because
its evidently been there longer....
it stays in the same place....
nevermind, i see why you need it....
their are none, then goes down to system, etc.
but their is always the chance that one will get boosted all the way up to
the priority lvl.
but I looked at Timer and TimerTask, now if i wanted to use this to
just count up to 100 min. how would i do that?
and if i need to compare the time to the time a job was supposed to be
input into the priority queue, basically, how does the Timer and TimerTask work?
can you just set a Timer like so...
Timer time = new Timer(1000, count ++)
where count will keep track of the seconds?
since timer counts in milliseconds....?
but when you put in a development job into the queue, it gets a
"boost" aka timer object put behind it, and if that "boost's" time
gives up before the job gets printed, then it gets boosted to the next up
same for client and system, but client's boost is 25 min, and system is 20.
and the "printer" is supposed to print 10pgs/min...
so about 1 pg every 6 seconds..
i think thats right....
so i need a constant timer for the Eventqueue, priority queue, and boost..
because the Eventqueue holds all the jobs in order by the time they are supposed to be inserted into the priority queue.
so say job 1 has time 2, then when the timer is at 2 min, job 1 gets placed into the priority queue, at the right postion and if its the first job, then it starts the printTimer, and if its not, then it goes to the correct priority in the queue..
The printer can run in yet another TimerTask. It pulls a job off the queue, computes how long the job will take (page count * 6 seconds), schedules itself to run again in that many seconds. If that works, you could get cute and make it display "Printing page n of n" every 6 seconds.
You only need one Timer to manage all the tasks.
A few interesting problems remain. What do you do if the queue is empty? How do you shut the thing down before the queue is empty?
This is a fun assignment. Keep us posted on progress!
The basic idea is you give a Task to the Timer and tell the Timer when to call run() on the Task. See if this sounds good:
See if you can make that run with the simplest possible queue - just one job loaded ahead of time.
and their are no example print simulation on the web lol
all the timer/timertask examples are very non-trivial and won't work for
me for some reason...
doesn't go over them or anything..
It's frustrating because I've never even heard of util.Timer or
util.TimerTask, and im about to be in software Engineering and
more upper level classes...
My point being, basically, is that im not going to be very prepared.
Originally posted by Justin Fox:
how am I supposed to instatiate a instance of TimerTask,
if its abstract?
You can't ofcourse, because it's abstract. You create a new subclass of TimerTask and implement the abstract method run() in your own subclass, and create an instance of your own subclass which you give to the Timer, just like the tutorial shows you.
or even if i make a new class like the example above and extend
TimerTask, when i create a new instance of that class, i'm still
going to get a non-static static reference error..
You create a new instance of a class by using the new operator:
By the way, this code you wrote doesn't look too good:
What happens here? In the constructor of class printEvent you create another printEvent object, by calling a non-existent no-args constructor (you'll get a compiler error for that). You are also missing semi-colons at the end of your statements.
Just create the printEvent object and the Timer in your main method. Look closely at the example in the tutorial and structure your class in the same way. Note that in the example, the class RemindTask is an inner class of the class Reminder. Class Reminder is not the TimerTask subclass (like you are trying to do it in your printEvent class).
Don't make the Timer object a member variable of the printEvent class and don't initialise the timer in a constructor of that class, it messes things up.
I'd find it simpler to use separate source files and top level classes than to use inner classes. Sometimes it seems like more typing and more files, but the concepts are just easier for me to keep up with.
A good challenge is to find a very small part of this you can make as simple as possible. That's why I hinted at a minimal queue that has only one item in it. That lets you focus on the printer and ignore the queuing stuff until later. I'm sure we could find even smaller bits to try first with a little time.
i need some help with a piece of my code tho...
// method void startPrinting();
this is the code that subtracts a page from the current printjob every
and after its done, it deletes the node its at, and then if the priority
queue has more in the queue, it keeps on printing those, but if it doesnt,
on to the system queue, if system has none, on to client etc, but if system does have a job, it prints it, and when its done, checks to see if
priority has gotten a job, and if not goes to nextNode to see if it has another...
same for the others...
here is the code that is calling startPrinting...
this code is just incrementing Arrival every minute, and comparing it
to the job time of the current Event, and if it is equal, then it inserts
it into the correct queue, and then "startPrinting()"...
but I am getting this error, and I've been looking for it for awhile,
i thought maybe the values were being inserted into the queues, but they are, here is the error msg..
as you can see job one arrived, but right after that it calls
startPrinting() and gets the nullPointerException,
help meh please,
like thread the Event list, while im threading the job queue?
because while im threading and inserting the jobs from the EventQueue to the
i need to be seaching for the best job to print, and i need to thread
the pages that are being printed....
stillRunning() could check any condition to know when to stop. In this case it might check to see if we've been running for more than 100 seconds:
You can always take the first job in the queue regardless of its priority. If you sort the queue by priority you'll always want to print the top job next.
I decided if the queue was empty to wait 1 second and try again. You might decide to break out of the loop.
The print() method can be just as clear:
Any of that give you ideas? See if you can make something like that work with a simple queue that doesn't shift around when jobs age. Then we can work the priority issue separately.
[ July 25, 2006: Message edited by: Stan James ]
but as for the pause(long milli) what is that a method to?...
cause i know you can do Thread.sleep(long milli);
it works good, except that it pauses the whole application...
i need the application to be inserting jobs by priority, AND
printing the highest priority at the same time..
now TimerTask would be perfect for the printing of the pages..
and thread works great for inputing the jobs by priority....
i still need some kind of method/getter to traverse the queue to extract
the number of pages....
hmm, which is:
either Priority,Sys,Client, or Development.getCurrentValue().getPages();
well, i have to go to work, ill be back later with more posts believe me lol
and thanks a lot dude..
See how pause(1000) reads better than 7 or 8 lines of code and avoids repetition? BTW: Make an empty catch clause only if you seriously know what's going on. It's almost always interesting to know that you've had an exception!
If you need the rest of the application to keep going while this happens, run it on its own thread. Say the code I showed was in a class Printer that implements Runnable ... your main() might do this ...
I'm curious about that doubly linked list for the queue. Is that a solid requirement?