7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 4905777
26 @summary PrintStream.println(Object) oversynchronized, can deadlock
27 */
28
29 import java.io.PrintStream;
30
31 public class OversynchronizedTest extends Thread {
32 private static TestObj testObj = new TestObj("This is a test.");
33 private static int loopNum = 100;
34
35 public void run() {
36 for(int i=0; i<loopNum; i++) {
37 testObj.test();
38
39 //passing an object to System.out.println might cause deadlock
40 //if the object has a synchronized toString() method.
41 //using System.out.println(testObj.toString()) won't have a problem
42 System.out.println(testObj);
43 }
44 }
45
46 public static void main(String args[]) throws Exception {
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 4905777
26 @summary PrintStream.println(Object) oversynchronized, can deadlock
27 @key randomness
28 */
29
30 import java.io.PrintStream;
31
32 public class OversynchronizedTest extends Thread {
33 private static TestObj testObj = new TestObj("This is a test.");
34 private static int loopNum = 100;
35
36 public void run() {
37 for(int i=0; i<loopNum; i++) {
38 testObj.test();
39
40 //passing an object to System.out.println might cause deadlock
41 //if the object has a synchronized toString() method.
42 //using System.out.println(testObj.toString()) won't have a problem
43 System.out.println(testObj);
44 }
45 }
46
47 public static void main(String args[]) throws Exception {
|