/** * Name a new thread. This method may or may not be used, it is up to the scheduling strategy to decide * to honor this. */ public String threadName() { return "neo4j." + groupName() + "-" + threadCounter.incrementAndGet(); }
ThreadPool( Group group, ThreadGroup parentThreadGroup ) { threadFactory = new GroupedDaemonThreadFactory( group, parentThreadGroup ); executor = group.buildExecutorService( threadFactory ); registry = new ConcurrentHashMap<>(); }
@Override public Thread newThread( @SuppressWarnings( "NullableProblems" ) Runnable job ) { Thread thread = new Thread( threadGroup, job, group.threadName() ) { @Override public String toString() { StringBuilder sb = new StringBuilder( "Thread[" ).append( getName() ); ThreadGroup group = getThreadGroup(); String sep = ", in "; while ( group != null ) { sb.append( sep ).append( group.getName() ); group = group.getParent(); sep = "/"; } return sb.append( ']' ).toString(); } }; thread.setDaemon( true ); return thread; }
private IllegalArgumentException newUnschedulableException( Group group ) { return new IllegalArgumentException( "Tasks cannot be scheduled directly to the " + group.groupName() + " group." ); } };
@Override public ForkJoinWorkerThread newThread( ForkJoinPool pool ) { // We do this complicated dance of allocating the ForkJoinThread in a separate thread, // because there is no way to give it a specific ThreadGroup, other than through inheritance // from the allocating thread. ForkJoinPool.ForkJoinWorkerThreadFactory factory = ForkJoinPool.defaultForkJoinWorkerThreadFactory; AtomicReference<ForkJoinWorkerThread> reference = new AtomicReference<>(); Thread allocator = newThread( () -> reference.set( factory.newThread( pool ) ) ); allocator.start(); do { try { allocator.join(); } catch ( InterruptedException ignore ) { } } while ( reference.get() == null ); ForkJoinWorkerThread worker = reference.get(); worker.setName( group.threadName() ); return worker; } }
ThreadPool( Group group, ThreadGroup parentThreadGroup ) { threadFactory = new GroupedDaemonThreadFactory( group, parentThreadGroup ); executor = group.buildExecutorService( threadFactory ); registry = new ConcurrentHashMap<>(); }
GroupedDaemonThreadFactory( Group group, ThreadGroup parentThreadGroup ) { this.group = group; threadGroup = new ThreadGroup( parentThreadGroup, group.groupName() ); }
@Override public Thread newThread( @SuppressWarnings( "NullableProblems" ) Runnable job ) { Thread thread = new Thread( threadGroup, job, group.threadName() ) { @Override public String toString() { StringBuilder sb = new StringBuilder( "Thread[" ).append( getName() ); ThreadGroup group = getThreadGroup(); String sep = ", in "; while ( group != null ) { sb.append( sep ).append( group.getName() ); group = group.getParent(); sep = "/"; } return sb.append( ']' ).toString(); } }; thread.setDaemon( true ); return thread; }
GroupedDaemonThreadFactory( Group group, ThreadGroup parentThreadGroup ) { this.group = group; threadGroup = new ThreadGroup( parentThreadGroup, group.groupName() ); }
@Override public ForkJoinWorkerThread newThread( ForkJoinPool pool ) { // We do this complicated dance of allocating the ForkJoinThread in a separate thread, // because there is no way to give it a specific ThreadGroup, other than through inheritance // from the allocating thread. ForkJoinPool.ForkJoinWorkerThreadFactory factory = ForkJoinPool.defaultForkJoinWorkerThreadFactory; AtomicReference<ForkJoinWorkerThread> reference = new AtomicReference<>(); Thread allocator = newThread( () -> reference.set( factory.newThread( pool ) ) ); allocator.start(); do { try { allocator.join(); } catch ( InterruptedException ignore ) { } } while ( reference.get() == null ); ForkJoinWorkerThread worker = reference.get(); worker.setName( group.threadName() ); return worker; } }
private IllegalArgumentException newUnschedulableException( Group group ) { return new IllegalArgumentException( "Tasks cannot be scheduled directly to the " + group.groupName() + " group." ); } };
/** * Name a new thread. This method may or may not be used, it is up to the scheduling strategy to decide * to honor this. */ public String threadName() { return "neo4j." + groupName() + "-" + threadCounter.incrementAndGet(); }