Scopri come trovare i migliori falegnami per le tue esigenze di falegnameria. In questo articolo, esploreremo suggerimenti utili per scegliere professionisti esperti, garantendo lavori di qualità per le tue ristrutturazioni e progetti di design. Non perdere l'occasione di valorizzare i tuoi spazi!
Trova professionisti vicino a te
Trova professionisti
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.kernel.impl.scheduler;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.neo4j.scheduler.Group;
import org.neo4j.scheduler.JobHandle;
class ThreadPoolJobScheduler extends AbstractJobScheduler
{
private final ExecutorService executorService;
private final AtomicLong jobCounter = new AtomicLong( 0 );
ThreadPoolJobScheduler( Group group, ExecutorService executorService, ThreadFactory threadFactory )
{
super( group, threadFactory );
this.executorService = executorService;
}
@Override
protected JobHandle submit( Runnable job )
{
return new ThreadPoolJobHandle( jobCounter.incrementAndGet(), executorService.submit( job ) );
}
@Override
public void close()
{
executorService.shutdown();
try
{
executorService.awaitTermination( 10, TimeUnit.SECONDS );
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt();
}
}
private class ThreadPoolJobHandle implements JobHandle
{
private final long id;
private final java.util.concurrent.Future future;
ThreadPoolJobHandle( long id, java.util.concurrent.Future future )
{
this.id = id;
this.future = future;
}
@Override
public long getId()
{
return id;
}
@Override
public boolean cancel( boolean mayInterruptIfRunning )
{
return future.cancel( mayInterruptIfRunning );
}
}
}