Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/appthread.java
41155 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.gctests.gctest03;2425import nsk.share.test.*;26import nsk.share.gc.*;2728//import Tree;29//import LocalRandom;3031// remove the nodes whose key is the multiple of key from the tree32class Redthread extends Thread {33Tree optree;34int key;3536Redthread(Tree tr, int k)37{38optree = tr;39key = k;40}4142public void run() {43int maxsz = (1024 * 64); // 64k44int i = 1;45int sz;4647sz = 1;4849while ( optree.isempty() == false)50{51DataNode d;52// System.out.println(getName() + i);53// sz = (key * i) % maxsz;54try55{56d = new DataNode(sz);57}58catch (DataNodeException e)59{60//System.out.println(getName() + " exiting");61return;62}63if (optree.remove(d))64// System.out.println(getName() + " removes " + sz);65i++;66try67{68sleep(3);69}70catch(InterruptedException e) {}7172// optree.sort1();73sz++;74}75}76}7778// add the nodes whose key is the multiple of key from the tree79class Bluethread extends Thread {80Tree optree;81int key;82private int loopcount = 0;8384Bluethread(Tree tr, int k)85{86optree = tr;87key = k;88}8990public void setloop(int n)91{92loopcount = n;93}9495public void run()96{97int i;98int sz;99int maxsz = (1024 * 64); // 64k100101i = 1; sz = 0;102while ( (loopcount== 0) ? true : (i < loopcount) )103{104sz = (key * i) % maxsz;105DataNode d;106107try108{109d= new DataNode(sz);110}111catch (DataNodeException e)112{113//System.out.println(getName() + " exiting");114return;115}116117TreeNode t = new TreeNode(d);118// System.out.println(getName() + i);119if ( optree.search(d) == null )120{121optree.insert(t);122// System.out.println(getName() + " insert " + sz);123}124//optree.sort1();125i++;126try127{128sleep(5);129}130catch(InterruptedException e) {}131}132}133}134135class Yellowthread extends Thread {136Tree optree;137int key; // data to be moved from the tree138139Yellowthread(Tree tr, int k)140{141optree = tr;142key = k;143}144145// remove the nodes whose key is the multiple of key from the tree146public void run()147{148int i = 1;149while ( true )150{151DataNode d;152try153{154d = new DataNode(key*i);155}156catch (DataNodeException e)157{158//System.out.println(getName() + " exiting");159return;160}161TreeNode t = optree.search(d);162/* if ( t != null ) System.out.println(getName() + ": search = " +163* (t.getData()).getkey());164*/165i++;166if ( LocalRandom.random() < 0.668 )167{168try169{170sleep(5);171}172catch(InterruptedException e) {}173}174}175}176}177178public class appthread {179}180181182