@Before
public void initializeOpenEJB() throws NamingException {
Context ctxt = null;
 try {
 Properties p = new Properties();
 p.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
 ctxt = new InitialContext(p);
ctxt.bind("inject", this);
}
 finally {
try {
ctxt.close();
 }
catch (NamingException ignored) {
 }
}
}

?


don't do it this way, use @BeforeClass and do the close in @AfterClass. the
bind (only it) in @Before is fine

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Edison Xu <xeseo2...@gmail.com>

> I've created some sample codes and upload to github just now.
> https://github.com/EdisonXu/Test/tree/master/ejb-intro
>
> the time consumed:
> Without test:
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Reactor Summary:
> [INFO]
> [INFO] Introduction of EJB ............................... SUCCESS [0.779s]
> [INFO] Message Client .................................... SUCCESS [2.280s]
> [INFO] Message Server .................................... SUCCESS [1.411s]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 5.251s
> [INFO] Finished at: Wed Sep 19 16:31:38 CST 2012
> [INFO] Final Memory: 21M/494M
> [INFO]
> ------------------------------------------------------------------------
>
> With test:
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Reactor Summary:
> [INFO]
> [INFO] Introduction of EJB ............................... SUCCESS [0.847s]
> [INFO] Message Client .................................... SUCCESS [7.180s]
> [INFO] Message Server .................................... SUCCESS [9.784s]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 18.716s
> [INFO] Finished at: Wed Sep 19 16:30:54 CST 2012
> [INFO] Final Memory: 32M/494M
> [INFO]
> ------------------------------------------------------------------------
>
> In this small case, time gap between two total time is about 13s. The
> container launched twice.
> I'm not running this test project on Server but dev machine, and I believe
> it will event cost less on server.
>
> Anyway, the time cost will increase with the number of sub-modules of the
> project. Is there anyway to avoid it?
> Thanks :)
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657520.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Reply via email to