Source Code Cross Referenced for TestPrimroseStandalone.java in  » Database-JDBC-Connection-Pool » Primrose » uk » org » primrose » test » 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 » Database JDBC Connection Pool » Primrose » uk.org.primrose.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *	Library name : Primrose - A Java Database Connection Pool.
003:         *	Published by Ben Keeping, http://primrose.org.uk .
004:         *	Copyright (C) 2004 Ben Keeping, primrose.org.uk
005:         *	Email: Use "Contact Us Form" on website
006:         *
007:         *	This library is free software; you can redistribute it and/or
008:         *	modify it under the terms of the GNU Lesser General Public
009:         *	License as published by the Free Software Foundation; either
010:         *	version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *	This library is distributed in the hope that it will be useful,
013:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *	Lesser General Public License for more details.
016:         *
017:         *	You should have received a copy of the GNU Lesser General Public
018:         *	License along with this library; if not, write to the Free Software
019:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */package uk.org.primrose.test;
021:
022:        import uk.org.primrose.pool.core.PoolLoader;
023:        import uk.org.primrose.vendor.standalone.*;
024:        import javax.sql.*;
025:        import java.sql.*;
026:        import javax.naming.*;
027:        import java.util.List;
028:
029:        /**
030:         * 
031:         * This class demonstrates how you may load primrose in a standalone
032:         * Java application.
033:         * 
034:         * It first loads a web console, to provide an interface for viewing pool activity
035:         * and stopping/restarting pools on the fly.
036:         * 
037:         * Then it loads some pools from a defined pool coniguration file.
038:         * 
039:         * Note that in your application, you do not have to load the web console -
040:         * it is entirely optional.
041:         * 
042:         */
043:        public class TestPrimroseStandalone {
044:            public static void main(String args[]) throws Exception, Throwable {
045:                if (args.length != 6) {
046:                    System.out
047:                            .println("java uk.org.primrose.test.TestPrimroseStandalone  <config file> <webconsole_username> <webconsole_password> <webconsole_port> <log file name> <log level>");
048:                    System.out
049:                            .println("EG:\njava uk.org.primrose.test.TestPrimroseStandalone /usr/primrose/conf/primrose.conf admin admin 8090 /var/log/primrose_console.log verbose,info,warn,error,crisis");
050:
051:                    System.exit(0);
052:                }
053:
054:                // Start the web console
055:                PrimroseWebConsoleLoader.load(args[1], args[2], Integer
056:                        .parseInt(args[3]), args[4], args[5]);
057:
058:                // Load the pools
059:                List<String> loadedPoolNames = PrimroseLoader.load(args[0],
060:                        true);
061:
062:                // Get a pool name from the first loaded pool 
063:                // to run our test with
064:                String poolName = loadedPoolNames.get(0);
065:
066:                new TestPrimroseStandalone().runTest(poolName);
067:
068:                //Thread.sleep(10000);
069:
070:                //System.exit(0);
071:            }
072:
073:            public void runTest(String poolName) throws Throwable {
074:                int i = 0;
075:                while (i++ < 20) {
076:                    new RunThread(poolName).run();
077:                }
078:                /*
079:                int connectionsToGet = 30;
080:                int cycles = 10;
081:                
082:                int [] sleeps = new int[5];
083:                sleeps[0] = 100;
084:                sleeps[1] = 200;
085:                sleeps[2] = 50;
086:                sleeps[3] = 10000;
087:                sleeps[4] = 10;
088:                for (int k = 0; k < cycles; k++) {
089:                	for (int i = 0; i < sleeps.length; i++) {
090:                		int j = 0;				
091:                		while (j++ < connectionsToGet) {
092:                			new RunThread(poolName).start();
093:                		}
094:                		Thread.sleep(sleeps[i]);
095:                		System.out.println("Sleep : " +sleeps[i]);
096:                	}
097:                }
098:                 */
099:            }
100:
101:            /**
102:             * 
103:             * Perform a test on the newly loaded pool
104:             *
105:             */
106:            class RunThread extends Thread {
107:                String poolName = null;
108:
109:                public RunThread(String poolName) {
110:                    this .poolName = poolName;
111:                }
112:
113:                public void run() {
114:                    try {
115:                        //System.out.println("start ...");
116:                        Context ctx = new InitialContext();
117:                        DataSource ds = (DataSource) ctx
118:                                .lookup("java:comp/env/" + poolName);
119:                        long now = System.currentTimeMillis();
120:                        Connection c = ds.getConnection();
121:                        System.out.println("got connection " + c + " in "
122:                                + (System.currentTimeMillis() - now)
123:                                + "ms from pool " + poolName);
124:                        Statement s = c.createStatement();
125:                        ResultSet rs = s.executeQuery("select 1 from test");
126:                        //Thread.sleep(100);
127:                        while (rs.next()) {
128:                            rs.getString(1);
129:                        }
130:                        rs.close();
131:                        s.close();
132:                        //c.close();;
133:                    } catch (Exception e) {
134:                        e.printStackTrace();
135:                    }
136:                }
137:
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.