b**********5 发帖数: 7881 | 1 You are writing a simulation for a print server. This print
server can accept jobs from 3 places - network, USB, or operator. It can
dispatch only one job at a time. Each input job should contain an integer t
which is the time in seconds it will take to process the job. Write a multi-
threaded program to simulate the server and provide some simulated load with
jobs. Think, of some interesting statistics your program should emit and
code them in. |
b**********5 发帖数: 7881 | |
n*******s 发帖数: 17267 | |
e********2 发帖数: 495 | 4 不会。
t
multi-
with
【在 b**********5 的大作中提到】 : You are writing a simulation for a print server. This print : server can accept jobs from 3 places - network, USB, or operator. It can : dispatch only one job at a time. Each input job should contain an integer t : which is the time in seconds it will take to process the job. Write a multi- : threaded program to simulate the server and provide some simulated load with : jobs. Think, of some interesting statistics your program should emit and : code them in.
|
b**********5 发帖数: 7881 | 5 up, 一家的online test。。。 除了这题, 他妈的还有其他三道题。。。 要45分钟
做完。。 |
g*****g 发帖数: 34805 | 6 Use a blocking queue, this is a typical producer/consumer multi-thread
question.
t
multi-
with
【在 b**********5 的大作中提到】 : You are writing a simulation for a print server. This print : server can accept jobs from 3 places - network, USB, or operator. It can : dispatch only one job at a time. Each input job should contain an integer t : which is the time in seconds it will take to process the job. Write a multi- : threaded program to simulate the server and provide some simulated load with : jobs. Think, of some interesting statistics your program should emit and : code them in.
|
b**********5 发帖数: 7881 | 7 I know u need a queue, but how do u write USB...sockets and shit? and then
should I use a registed callback to do statistics like actual time used to
process tasks?
【在 g*****g 的大作中提到】 : Use a blocking queue, this is a typical producer/consumer multi-thread : question. : : t : multi- : with
|
g*****g 发帖数: 34805 | 8 No, it's called simulation, all you need is label the producers as "USB"
blah blah and print out as such. You register the timestamp when the job is
produced and calculate the diff when the job is consumed, it's exactly the
basic P/C question.
【在 b**********5 的大作中提到】 : I know u need a queue, but how do u write USB...sockets and shit? and then : should I use a registed callback to do statistics like actual time used to : process tasks? :
|
g*****g 发帖数: 34805 | 9 Executors.newFixedThreadPool(1);
class PrintTask extends Callable {
public PrintTask(DeviceEnum device, int printTime);
}
record current timestamp and use finish time to come up with statistics is
enough.
Not rocket science. |
b**********5 发帖数: 7881 | 10 are you saying the following is enough??!!!
public class Printer {
main () {
BlocingQueue q...
Thread USBThread = new Thread (new Producer(q));
Thread USB1Thread = new Thread (new Producer(q));
Thread consumerThread = new Thread (new Consumer(q));
thread.starts();
thread.start(); ...
}
}
then the USBthread just add dummy tasks to the queue??! I just create a
dummy class Task? I don't need no bytestreams or shit like that?!
and in the consumer thread, just take one by one?
【在 b**********5 的大作中提到】 : I know u need a queue, but how do u write USB...sockets and shit? and then : should I use a registed callback to do statistics like actual time used to : process tasks? :
|
|
|
b**********5 发帖数: 7881 | 11 got it. thanks. so just a simulation with one consumer and producer thread
.
【在 g*****g 的大作中提到】 : Executors.newFixedThreadPool(1); : class PrintTask extends Callable { : public PrintTask(DeviceEnum device, int printTime); : } : record current timestamp and use finish time to come up with statistics is : enough. : Not rocket science.
|
g*****g 发帖数: 34805 | 12 No, it's one consumer and any number of producers.
thread
【在 b**********5 的大作中提到】 : got it. thanks. so just a simulation with one consumer and producer thread : .
|
b**********5 发帖数: 7881 | 13 ? So i am assuming it will be a queue of PrintTask u defined above.
So are u saying i should start 3 producer threads for 3 devices? But if u
already include device enum in the printtask, then why do u need 3 different
threads for each?
【在 g*****g 的大作中提到】 : No, it's one consumer and any number of producers. : : thread
|
g*****g 发帖数: 34805 | 14 You don't need to start any producer thread. threadpool is about consumer.
An enum is enough to mark the producer.
different
【在 b**********5 的大作中提到】 : ? So i am assuming it will be a queue of PrintTask u defined above. : So are u saying i should start 3 producer threads for 3 devices? But if u : already include device enum in the printtask, then why do u need 3 different : threads for each?
|
b**********5 发帖数: 7881 | 15 now i am back to square one... if u not gonna have any producer thread, then
how is the queue of PrintTasks getting added?
【在 g*****g 的大作中提到】 : You don't need to start any producer thread. threadpool is about consumer. : An enum is enough to mark the producer. : : different
|
d**p 发帖数: 510 | 16 Operator, USB and network should take care of producing tasks. Printer can
provide a function to accept these tasks and insert into queue. |
g*****g 发帖数: 34805 | 17 For simulation,you just need to demonstrate the ability submit each task
asynchronously. That's why each task is a callable future.
e.g.
Future f = threadpool.submit(new PrintTask(USB, 10));
different
【在 b**********5 的大作中提到】 : ? So i am assuming it will be a queue of PrintTask u defined above. : So are u saying i should start 3 producer threads for 3 devices? But if u : already include device enum in the printtask, then why do u need 3 different : threads for each?
|