283N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
283N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
283N/A *
283N/A * This code is free software; you can redistribute it and/or modify it
283N/A * under the terms of the GNU General Public License version 2 only, as
283N/A * published by the Free Software Foundation.
283N/A *
283N/A * This code is distributed in the hope that it will be useful, but WITHOUT
283N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
283N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
283N/A * version 2 for more details (a copy is included in the LICENSE file that
283N/A * accompanied this code).
283N/A *
283N/A * You should have received a copy of the GNU General Public License version
283N/A * 2 along with this work; if not, write to the Free Software Foundation,
283N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
283N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
283N/A */
283N/A
283N/A
283N/A/* @test
283N/A * @summary verify thread interruption doesn't affect font file reading.
283N/A * @bug 6640532
283N/A */
283N/A
283N/Aimport java.awt.*;
283N/A
283N/Apublic class FontThread extends Thread {
283N/A
283N/A String fontName = "Dialog";
283N/A static FontThread thread1;
283N/A static FontThread thread2;
283N/A static FontThread thread3;
283N/A
283N/A public static void main(String args[]) throws Exception {
283N/A thread1 = new FontThread("SansSerif");
283N/A thread2 = new FontThread("Serif");
283N/A thread3 = new FontThread("Monospaced");
283N/A thread1.dometrics(60); // load classes first
283N/A thread1.start();
283N/A thread2.start();
283N/A thread3.start();
283N/A InterruptThread ithread = new InterruptThread();
283N/A ithread.setDaemon(true);
283N/A ithread.start();
283N/A thread1.join();
283N/A thread2.join();
283N/A thread3.join();
283N/A }
283N/A
283N/A FontThread(String font) {
283N/A super();
283N/A this.fontName = font;
283N/A }
283N/A
283N/A public void run() {
283N/A System.out.println("started "+fontName); System.out.flush();
283N/A dometrics(4000);
283N/A System.out.println("done "+fontName); System.out.flush();
283N/A }
283N/A
283N/A private void dometrics(int max) {
283N/A Font f = new Font(fontName, Font.PLAIN, 12);
283N/A FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
283N/A for (char i=0;i<max;i++) {
283N/A if (f.canDisplay(i)) fm.charWidth(i);
283N/A }
283N/A }
283N/A
283N/A static class InterruptThread extends Thread {
283N/A public void run() {
283N/A while (true) {
283N/A try {
283N/A Thread.sleep(1);
283N/A } catch (InterruptedException e) {
283N/A }
283N/A thread1.interrupt();
283N/A thread2.interrupt();
283N/A thread3.interrupt();
283N/A }
283N/A }
283N/A }
283N/A}