Source Code Cross Referenced for EventQueueLockThread.java in  » Scripting » jacl » tests » 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 » Scripting » jacl » tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tests;
002:
003:        import tcl.lang.*;
004:
005:        // This class is designed to test the mutual exclusion approach
006:        // of the tcl.lang.Notifier class. An event should be added to
007:        // the queue right away, even if another time consuming event
008:        // is being processed. This class is used in
009:        // tcljava/TclEvent.test in test TclEvent-1.5.
010:
011:        public class EventQueueLockThread extends Thread {
012:            private Interp interpInOtherThread;
013:
014:            public boolean slow_event_started = false;
015:            public boolean slow_event_finished = false;
016:            public boolean thread_finished = false;
017:            public boolean test_passed = false;
018:
019:            private static final boolean debug = false;
020:
021:            public EventQueueLockThread(Interp i) {
022:                interpInOtherThread = i;
023:            }
024:
025:            public void run() {
026:                if (debug) {
027:                    System.out.println("running EventQueueLockThread");
028:                }
029:
030:                // In this new thread, queue an event that will take a
031:                // long time to process, it will actually be processed
032:                // in the original thread.
033:
034:                TclEvent event = new TclEvent() {
035:                    public int processEvent(int flags) {
036:                        if (debug) {
037:                            System.out.println("started processing slow event");
038:                        }
039:                        slow_event_started = true;
040:                        try {
041:                            Thread.sleep(10000);
042:                        } catch (InterruptedException e) {
043:                        }
044:                        slow_event_finished = true;
045:                        if (debug) {
046:                            System.out
047:                                    .println("finished processing slow event");
048:                        }
049:                        return 1;
050:                    }
051:                };
052:
053:                // Add the event to the thread safe event queue
054:                if (debug) {
055:                    System.out.println("about to add slow event to queue");
056:                }
057:                interpInOtherThread.getNotifier().queueEvent(event,
058:                        TCL.QUEUE_TAIL);
059:
060:                // Now wait around a bit to give the notifier a
061:                // chance to start processing the slow event.
062:
063:                try {
064:                    Thread.sleep(2000);
065:                } catch (InterruptedException e) {
066:                }
067:
068:                if (slow_event_started == false) {
069:                    throw new RuntimeException("slow event was not started");
070:                }
071:                if (slow_event_finished == true) {
072:                    throw new RuntimeException(
073:                            "slow event was already finished");
074:                }
075:
076:                TclEvent other_event = new TclEvent() {
077:                    public int processEvent(int flags) {
078:                        if (debug) {
079:                            System.err.println("processed other event");
080:                        }
081:                        return 1;
082:                    }
083:                };
084:
085:                // This event should get added to the queue right away,
086:                // it should not get queued after the slow event has
087:                // finished running.
088:
089:                if (debug) {
090:                    System.err.println("about to add other event to queue");
091:                }
092:                interpInOtherThread.getNotifier().queueEvent(other_event,
093:                        TCL.QUEUE_TAIL);
094:                if (debug) {
095:                    System.err.println("added other event to queue");
096:                }
097:
098:                if (slow_event_finished == false) {
099:                    if (debug) {
100:                        System.err
101:                                .println("queueEvent returned before slow event finished");
102:                    }
103:                    test_passed = true;
104:                } else {
105:                    if (debug) {
106:                        System.err
107:                                .println("slow event finished before queueEvent returned");
108:                    }
109:                }
110:
111:                thread_finished = true;
112:
113:                if (debug) {
114:                    System.err.println("done running EventQueueLockThread");
115:                }
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.