Source Code Cross Referenced for ThreadStateMapping.java in  » Scripting » jython » org » python » core » 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 » jython » org.python.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.python.core;
002:
003:        /**
004:         * 
005:         * @deprecated Java 1 support is deprecated -- remove.
006:         *
007:         */
008:        class ThreadStateMapping {
009:            //Java 1 support is deprecated -- remove this check.
010:            private static boolean checkedJava2 = false;
011:
012:            public static ThreadStateMapping makeMapping() {
013:                if (!checkedJava2) {
014:                    checkedJava2 = true;
015:                    String version = System.getProperty("java.version");
016:                    if (version.compareTo("1.2") >= 0) {
017:                        try {
018:                            Class c = Class
019:                                    .forName("org.python.core.ThreadStateMapping2");
020:                            return (ThreadStateMapping) c.newInstance();
021:                        } catch (Throwable t) {
022:                        }
023:                    }
024:                }
025:                return new ThreadStateMapping();
026:            }
027:
028:            // There are hacks that could improve performance slightly in the
029:            // interim, but I'd rather wait for the right solution.
030:            private static java.util.Hashtable threads;
031:
032:            private static ThreadState cachedThreadState;
033:
034:            // Mechanism provided by Drew Morrissey and approved by JimH which
035:            // occasionally cleans up dead threads, preventing the hashtable from
036:            // leaking memory when many threads are used (e.g. in an embedded
037:            // application).
038:            //
039:            // counter of additions to the threads table
040:            private static int additionCounter = 0;
041:
042:            // maximum number of thread additions before cleanup is triggered
043:            private static final int MAX_ADDITIONS = 25;
044:
045:            public ThreadState getThreadState(PySystemState newSystemState) {
046:                Thread t = Thread.currentThread();
047:                ThreadState ts = cachedThreadState;
048:                if (ts != null && ts.thread == t) {
049:                    return ts;
050:                }
051:
052:                if (threads == null) {
053:                    threads = new java.util.Hashtable();
054:                }
055:
056:                ts = (ThreadState) threads.get(t);
057:                if (ts == null) {
058:                    if (newSystemState == null) {
059:                        Py.writeDebug("threadstate", "no current system state");
060:                        // t.dumpStack();
061:                        newSystemState = Py.defaultSystemState;
062:                    }
063:                    ts = new ThreadState(t, newSystemState);
064:                    // System.err.println("new ts: "+ts+", "+ts.systemState);
065:                    threads.put(t, ts);
066:                    // increase the counter each time a thread reference is added
067:                    // to the table
068:                    additionCounter++;
069:                    if (additionCounter > MAX_ADDITIONS) {
070:                        cleanupThreadTable();
071:                        additionCounter = 0;
072:                    }
073:                }
074:                cachedThreadState = ts;
075:                // System.err.println("returning ts: "+ts+", "+ts.systemState);
076:                return ts;
077:            }
078:
079:            /**
080:             * Enumerates through the thread table looking for dead thread references
081:             * and removes them. Called internally by getThreadState(PySystemState).
082:             */
083:            private void cleanupThreadTable() {
084:                // loop through thread table removing dead thread references
085:                for (java.util.Enumeration e = threads.keys(); e
086:                        .hasMoreElements();) {
087:                    try {
088:                        Object key = e.nextElement();
089:                        ThreadState tempThreadState = (ThreadState) threads
090:                                .get(key);
091:                        if ((tempThreadState != null)
092:                                && (tempThreadState.thread != null)
093:                                && !tempThreadState.thread.isAlive()) {
094:                            threads.remove(key);
095:                        }
096:                    } catch (ClassCastException exc) {
097:                        // XXX: we should throw some type of exception here
098:                    }
099:                }
100:            }
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.