Skip to content

Infinite size of Threads.asyncJobs #264

Open
@roneigebert

Description

@roneigebert

I think we have a problem in asyncJobs queue.
I see that this queue is used in shutdown, but, executorService.awaitTermination can be a good alternative, right?

@RunWith(KikahaRunner.class)
public class ThreadsTest {

    Threads threads = Threads.elasticPool();

    final AtomicInteger counter = new AtomicInteger(0);
    final int numberOfRunnables = 1000000;

    @Test
    @SneakyThrows
    public void testThreads(){
        int i = 0;
        while ( i++ < numberOfRunnables )
            threads.submit( counter::incrementAndGet );
        Thread.sleep( 2000 );
        val asyncJobsField = threads.getClass().getDeclaredField( "asyncJobs" );
        asyncJobsField.setAccessible( true );
        val asyncJobs = (Queue)asyncJobsField.get( threads );
        assertEquals( numberOfRunnables, counter.get() );
        assertEquals( 0, asyncJobs.size() ); // test fails here - size is 1000000!
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions