我有 10 名工人名单的代码和以下两种方法:
public void demoDeques() {
int maxSizeOfJobDeque = 3;
Producer producer = new ProducerImpl( maxSizeOfJobDeque );
Logger.debug( "WorkFlowEngineImpl : " +
"Creating Workers and adding them to allocator" );
List<Worker> workerList = buildWorkerList( producer );
Logger.debug( "WorkFlowEngineImpl : " +
"Assigning some jobs to the workers. " +
"The workers have not been started yet");
for ( int i=1; i<4; i++ ) {
producer.assign( new JobImpl( "job " + i, i ) );
try {
Thread.sleep( 4000 );
} catch( InterruptedException e ) {
e.printStackTrace();
}
}
Logger.debug( "WorkFlowEngineImpl : " + "Starting the workers" );
startWorkersAndWait5Seconds( workerList );
Logger.debug( "WorkFlowEngineImpl : " +
"Assigning some more jobs to the " +
"started workers" );
for ( int i=4; i<7; i++ ) {
producer.assign( new JobImpl( "Job " + i, i ) );
try {
Thread.sleep( 4000 );
} catch( InterruptedException e ) {
e.printStackTrace();
}
}
Logger.debug( "WorkFlowEngineImpl : " + "Assigning More Jobs" );
for ( int i=7; i<11; i++ ) {
producer.assign( new JobImpl( "job" + i, i ) );
try {
Thread.sleep( 4000 );
} catch( InterruptedException e ) {
e.printStackTrace();
}
}
}
生产商:
public synchronized void assign( Job job ) {
Set<Worker> workerSet = jobMap.keySet();
LinkedBlockingDeque<Job> jobQueue;
StringBuffer sb;
for ( Worker worker : workerSet ) {
jobQueue = jobMap.get( worker );
sb = new StringBuffer();
sb.append( "Assigning job " );
sb.append( job.getJobNumber() );
sb.append( " to " );
sb.append( worker );
sb.append( "'s jobs Deque" );
Logger.debug( "Producer : " + sb.toString() );
if ( ! jobQueue.offerFirst( job ) ) {
jobQueue.pollLast();
jobQueue.offerFirst( job );
}
}
}
我正在尝试更改这两种方法,以便分配器有一个包含 100 个工作的列表,然后以这样的方式进行分配,即十个工人中的每一个在时间上最多分配三个工作,直到达到 100 个,即工人一个需要工作 1,2,3 工人 2 需要 4,5,6,所以当工人 10 到达时,它会返回给工人 1 分配三个工作,直到达到第 100 个工作,然后它会停止并警告所有工作都已分配。请帮助我被卡住了....