Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Threads and Synchronization


need help on ExecutorService?


Hi friends,We have a BeanLocator class in which we look up EJBs needed. this is a utility class that uses InitialContext of the EJBthere are many classes that are not EJBs so we can't inject the EJB services into them. That is why we create a simple locator.now I am going to increase the performance of accessing this locator. currently the methods of this locator are synchronized and it is created as a singleton.now this is the code I am using for the better performance. since this is first time I am using ExecutorService and the concept is a bit strange for me I would like you help me if this works fine and whether this is thread safe or not.thanks in advancehere is the code:code:public class BeanLocators {private static BeanLocators me = new BeanLocators();BeanLocator locator = new BeanLocator();private ExecutorService service = Executors.newCachedThreadPool(new ThreadFactory() {public Thread newThread(Runnable r) {return new Thread(r);};});public static <T> T get(Class<T> klass) {Future<BeanLocator> f = me.service.submit(new Callable<BeanLocator>() {public BeanLocator call() throws Exception {return me.locator;}});try {return f.get().get(klass);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ExecutionException e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}}the client classes will use as follows:code:MyEJBNo1 ejb1 = BeanLocators.getInstance().get(MyEJBNo1.class);MyEJBNo2 ejb2 = BeanLocators.getInstance().get(MyEJBNo2.class);please note that we can use BeanLocator (without s) individually but because it needs to be initialized so this creation has expensive cost and we need to create it once.[ July 22, 2008: Message edited by: mohammad norouzee ][ July 22, 2008: Message edited by: mohammad norouzee ]

   
   

   
   
      Any idea?


Related Links

thread
sleep() vs suspend() and stop() vs volatile
Please provide me the program of Bounded-Buffer problem
Class Lock and Object Lock
monitors / owners
Polling/Triggering thread
Periodically task performing thread
Thread Methods
use thread to stop application hanging
Killing a Process
holdsLock is working strange
Ending a thread without ending the JVM
thread newbie
Hashtables are synchronized...
atomicity & thread safety with primitives
How to speed up Batch Process