ThreadPoolExecutor keepAliveTime != 0 || allowCoreThreadTimeOut (2)
Aleksey Shipilev
aleksey.shipilev at oracle.com
Tue May 6 13:48:17 UTC 2014
Thanks again, committed:
http://hg.openjdk.java.net/code-tools/jcstress/rev/a23e3689382c
-Aleksey
On 05/06/2014 01:42 PM, Pavel Rappo wrote:
> The previous email I sent appeared to have no patch attached to it. I will add it inlined this time. Sorry for that.
>
> Thanks
> -Pavel
>
> diff -r b7cb13e9f459 tests-custom/src/main/java/org/openjdk/jcstress/tests/executors/ThreadPoolExecutorKeepAliveTest.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/executors/ThreadPoolExecutorKeepAliveTest.java Tue May 06 10:24:30 2014 +0100
> @@ -0,0 +1,63 @@
> +/*
> + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> + *
> + * This code is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 only, as
> + * published by the Free Software Foundation. Oracle designates this
> + * particular file as subject to the "Classpath" exception as provided
> + * by Oracle in the LICENSE file that accompanied this code.
> + *
> + * This code 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
> + * version 2 for more details (a copy is included in the LICENSE file that
> + * accompanied this code).
> + *
> + * You should have received a copy of the GNU General Public License version
> + * 2 along with this work; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
> + * or visit www.oracle.com if you need additional information or have any
> + * questions.
> + */
> +package org.openjdk.jcstress.tests.executors;
> +
> +import org.openjdk.jcstress.annotations.Actor;
> +import org.openjdk.jcstress.annotations.Arbiter;
> +import org.openjdk.jcstress.annotations.JCStressTest;
> +import org.openjdk.jcstress.annotations.State;
> +import org.openjdk.jcstress.infra.results.LongResult2;
> +
> +import java.util.concurrent.ArrayBlockingQueue;
> +import java.util.concurrent.ThreadPoolExecutor;
> +import java.util.concurrent.TimeUnit;
> +
> + at JCStressTest
> + at State
> +public class ThreadPoolExecutorKeepAliveTest {
> +
> + public final ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 2, 1L,
> + TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(2));
> +
> + @Actor
> + public void actor1() {
> + try {
> + pool.allowCoreThreadTimeOut(true);
> + } catch (IllegalArgumentException ignored) {}
> + }
> +
> + @Actor
> + public void actor2() {
> + try {
> + pool.setKeepAliveTime(0, TimeUnit.MILLISECONDS);
> + } catch (IllegalArgumentException ignored) {}
> + }
> +
> + @Arbiter
> + public void actor3(LongResult2 r) {
> + r.r1 = pool.allowsCoreThreadTimeOut() ? 1 : 0;
> + r.r2 = pool.getKeepAliveTime(TimeUnit.MILLISECONDS);
> + }
> +}
> diff -r b7cb13e9f459 tests-custom/src/main/resources/org/openjdk/jcstress/desc/executors.xml
> --- a/tests-custom/src/main/resources/org/openjdk/jcstress/desc/executors.xml Mon May 05 23:05:17 2014 +0400
> +++ b/tests-custom/src/main/resources/org/openjdk/jcstress/desc/executors.xml Tue May 06 10:24:30 2014 +0100
> @@ -1,6 +1,6 @@
> <!--
>
> - Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
> + Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
> DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>
> This code is free software; you can redistribute it and/or modify it
> @@ -54,5 +54,40 @@
> </unmatched>
> </test>
>
> + <test name="org.openjdk.jcstress.tests.executors.ThreadPoolExecutorKeepAliveTest">
> + <contributed-by>Pavel Rappo (pavel.rappo at oracle.com)</contributed-by>
> + <description>
> + Tests if ThreadPoolExecutor invariant can be violated:
> + keepAliveTime == 0 ⇒ !allowCoreThreadTimeOut
> + </description>
> + <case>
> + <match>[1, 1]</match>
> + <expect>ACCEPTABLE</expect>
> + <description>
> + allowCoreThreadTimeOut had changed, and keepAliveTime failed to change.
> + </description>
> + </case>
> + <case>
> + <match>[0, 0]</match>
> + <expect>ACCEPTABLE</expect>
> + <description>
> + keepAliveTime had changed, and allowCoreThreadTimeOut failed to change.
> + </description>
> + </case>
> + <case>
> + <match>[1, 0]</match>
> + <expect>ACCEPTABLE_INTERESTING</expect>
> + <description>
> + The update under race can break the
> + (keepAliveTime == 0 ⇒ !allowCoreThreadTimeOut) invariant.
> + </description>
> + </case>
> + <unmatched>
> + <expect>FORBIDDEN</expect>
> + <description>
> + This case is not expected.
> + </description>
> + </unmatched>
> + </test>
>
> -</testsuite>
> \ No newline at end of file
> +</testsuite>
>
>
>
>
More information about the jcstress-dev
mailing list