Source Code Cross Referenced for ThreadGroup002Debuggee.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » ThreadReference » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.jdwp.ThreadReference 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */
018:
019:        /**
020:         * @author Anatoly F. Bondarenko
021:         * @version $Revision: 1.2 $
022:         */
023:
024:        /**
025:         * Created on 19.06.2006
026:         */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
029:        import org.apache.harmony.jpda.tests.share.SyncDebuggee;
030:
031:        public class ThreadGroup002Debuggee extends SyncDebuggee {
032:            public static final int THREAD_NUMBER_LIMIT = 6;
033:            public static final String THREAD_NAME_PATTERN = "ThreadGroup002Debuggee_Thread_";
034:            public static final String THREAD_GROUP_NAME_PATTERN = "ThreadGroup002Debuggee_Thread_Group_";
035:
036:            static ThreadGroup002Debuggee ThreadGroup002DebuggeeThis;
037:
038:            static volatile boolean allThreadsToFinish = false;
039:            static int createdThreadsNumber = 0;
040:            static volatile int startedThreadsNumber = 0;
041:
042:            static int firstThreadsNumber = 0;
043:
044:            static ThreadGroup002Debuggee_Thread[] ThreadGroup002DebuggeeThreads = null;
045:            static ThreadGroup[] ThreadGroup002DebuggeeThreadGroups = new ThreadGroup[2];
046:
047:            static Object waitTimeObject = new Object();
048:
049:            static void waitMlsecsTime(long mlsecsTime) {
050:                synchronized (waitTimeObject) {
051:                    try {
052:                        waitTimeObject.wait(mlsecsTime);
053:                    } catch (Throwable throwable) {
054:                        // ignore
055:                    }
056:                }
057:            }
058:
059:            static void sleepMlsecsTime(long mlsecsTime) {
060:                try {
061:                    Thread.sleep(mlsecsTime);
062:                } catch (Throwable throwable) {
063:                    // ignore
064:                }
065:            }
066:
067:            public void run() {
068:
069:                logWriter.println("--> ThreadGroup002Debuggee: START...");
070:                ThreadGroup002DebuggeeThis = this ;
071:                logWriter
072:                        .println("--> ThreadGroup002Debuggee: Create thread groups...");
073:                ThreadGroup002DebuggeeThreadGroups[0] = new ThreadGroup(
074:                        THREAD_GROUP_NAME_PATTERN + 0);
075:                ThreadGroup002DebuggeeThreadGroups[1] = new ThreadGroup(
076:                        THREAD_GROUP_NAME_PATTERN + 1);
077:
078:                logWriter
079:                        .println("--> ThreadGroup002Debuggee: Create and start tested threads...");
080:                try {
081:                    ThreadGroup002DebuggeeThreads = new ThreadGroup002Debuggee_Thread[THREAD_NUMBER_LIMIT];
082:                    for (int i = 0; i < THREAD_NUMBER_LIMIT; i++) {
083:                        ThreadGroup002DebuggeeThreads[i] = new ThreadGroup002Debuggee_Thread(
084:                                ThreadGroup002DebuggeeThreadGroups[i % 2], i);
085:                        ThreadGroup002DebuggeeThreads[i].start();
086:                        createdThreadsNumber++;
087:                    }
088:                } catch (Throwable thrown) {
089:                    logWriter
090:                            .println("--> ThreadGroup002Debuggee: Exception while creating threads: "
091:                                    + thrown);
092:                }
093:                logWriter
094:                        .println("--> ThreadGroup002Debuggee: Created threads number = "
095:                                + createdThreadsNumber);
096:
097:                while (startedThreadsNumber != createdThreadsNumber) {
098:                    waitMlsecsTime(100);
099:                }
100:                if (createdThreadsNumber != 0) {
101:                    logWriter
102:                            .println("--> ThreadGroup002Debuggee: All created threads are started!");
103:                }
104:
105:                synchronizer
106:                        .sendMessage(Integer.toString(createdThreadsNumber));
107:
108:                String mainThreadName = Thread.currentThread().getName();
109:                synchronizer.sendMessage(mainThreadName);
110:
111:                String mainThreadGroupName = Thread.currentThread()
112:                        .getThreadGroup().getName();
113:                synchronizer.sendMessage(mainThreadGroupName);
114:
115:                logWriter
116:                        .println("--> ThreadGroup002Debuggee: Wait for signal from test to continue...");
117:                String messageFromTest = synchronizer.receiveMessage(); // signal to continue or to finish
118:
119:                if (!messageFromTest.equals("FINISH")) {
120:                    logWriter
121:                            .println("--> ThreadGroup002Debuggee: Send signal to the first threads to finish...");
122:
123:                    firstThreadsNumber = createdThreadsNumber / 2;
124:                    for (int i = 0; i < firstThreadsNumber; i++) {
125:                        while (ThreadGroup002DebuggeeThreads[i].isAlive()) {
126:                            waitMlsecsTime(10);
127:                        }
128:                    }
129:                    logWriter
130:                            .println("--> ThreadGroup002Debuggee: First threads finished - number of finished threads = "
131:                                    + firstThreadsNumber);
132:
133:                    synchronizer
134:                            .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
135:
136:                    logWriter
137:                            .println("--> ThreadGroup002Debuggee: Wait for signal from test to finish...");
138:                    synchronizer.receiveMessage(); // signal to finish
139:                }
140:
141:                logWriter
142:                        .println("--> ThreadGroup002Debuggee: Send signal to all threads to finish and wait...");
143:                allThreadsToFinish = true;
144:
145:                for (int i = 0; i < createdThreadsNumber; i++) {
146:                    while (ThreadGroup002DebuggeeThreads[i].isAlive()) {
147:                        waitMlsecsTime(10);
148:                    }
149:                }
150:                logWriter
151:                        .println("--> ThreadGroup002Debuggee: All threads finished!");
152:
153:                logWriter.println("--> ThreadGroup002Debuggee: FINISH...");
154:
155:            }
156:
157:            public static void main(String[] args) {
158:                runDebuggee(ThreadGroup002Debuggee.class);
159:            }
160:
161:        }
162:
163:        class ThreadGroup002Debuggee_Thread extends Thread {
164:
165:            int threadNumber;
166:            int threadKind;
167:
168:            public ThreadGroup002Debuggee_Thread(ThreadGroup group,
169:                    int threadNumber) {
170:                super (group, ThreadGroup002Debuggee.THREAD_NAME_PATTERN
171:                        + threadNumber);
172:                this .threadNumber = threadNumber;
173:                threadKind = threadNumber % 3;
174:            }
175:
176:            public void run() {
177:                ThreadGroup002Debuggee parent = ThreadGroup002Debuggee.ThreadGroup002DebuggeeThis;
178:                synchronized (parent) {
179:                    ThreadGroup002Debuggee.startedThreadsNumber++;
180:                }
181:                while (!ThreadGroup002Debuggee.allThreadsToFinish) {
182:                    switch (threadKind) {
183:                    case 0:
184:                        ThreadGroup002Debuggee.waitMlsecsTime(100);
185:                        break;
186:                    case 1:
187:                        ThreadGroup002Debuggee.sleepMlsecsTime(100);
188:                    }
189:                    if (threadNumber < ThreadGroup002Debuggee.firstThreadsNumber) {
190:                        return;
191:                    }
192:                }
193:            }
194:        }
w__ww.__j___a__v_a2_s_.c___o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.