[EJB 3.0] - SELECT FOR UPDATE in Optimistic transactions
by paoletto
Hello!
I have this method executed concurrently in many threads (MDBs), which generates quite many OptimisticLockException.
I changed the datasource from HSQL to PostgreSQL and tried to add a
SELECT FOR UPDATE statement to act like a mutex
But why i keep getting OptimisticLockExceptions then?
did i do some mistake?
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| public Process fetchProcess_real(int subsystem) {
|
| String lockQuery = "SELECT * FROM BPS_SUBSYSTEM WHERE id = :id FOR UPDATE";
|
| String fetchQuery =
| "SELECT " +
| " p " +
| "FROM " +
| " Process AS p " +
| "WHERE " +
| " p.state = 0 AND " +
| " p.processQueue.id IN " +
| " (SELECT " +
| " pq.id " +
| " FROM " +
| " ProcessQueue AS pq " +
| " WHERE " +
| " (pq.subsystem.id = " +
| " (SELECT " +
| " s.id " +
| " FROM " +
| " Subsystem AS s " +
| " WHERE " +
| " (s.id = " + subsystem + ") AND " +
| " (s.connected = true) " +
| " ) " +
| " ) AND " +
| " (pq.connected = true) AND " +
| " (pq.curActiveProcesses < pq.maxActiveProcesses) " +
| " ) " +
| "ORDER BY p.priority ASC, p.id ASC";
|
| Query nquery = em.createNativeQuery(lockQuery,Subsystem.class);
| nquery.setParameter("id",subsystem);
| Subsystem subsys = (Subsystem) nquery.getSingleResult();
|
|
| Query query = em.createQuery(fetchQuery);
| query.setMaxResults(1);
| List<Process> ProcessList = query.getResultList();
| if ((ProcessList == null) || ProcessList.isEmpty()) return null;
|
| Process p = ProcessList.get(0);
| ProcessQueue pq = p.getProcessQueue();
|
| p.use();
| pq.incrementActive();
|
| em.merge(p);
| em.merge(pq);
|
| return p;
| }
|
(ps the method is called always with the same parameter)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103323#4103323
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103323
18 years, 8 months
[EJB/JBoss] - Re: Client can connect to Bean before jdbc is bound
by joerandom
jaikiran,
Thanks for the link, I'll check it out to see if adding this detection logic avoids the issue. However, I still think that I shouldn't have to check to make sure the server is totally up before I can connect to it.
For example, assume my clients are running happily. I then decide to bounce my server for some reason (or perhaps my server goes down and needs to be restarted). My clients are unaware of the bounce, and just try to connect to the server as normal when they are done with their calculations (they connect using a remote JNDI lookup). Due to the issue I am seeing, the lookup will be successful, but their first method call on the bean will fail because JBoss has not bound the jdbc entry to my bean yet.
Right now I just handle the error on the server and client side and have the client try again later when JBoss has completed deploying my bean. I can certainly add logic to check to make sure the server is up before my clients connect (every time they try to connect), but it really seems like JBoss should not allow remote connections to beans that are not fully deployed. I would rather have the remote lookup fail due to an incomplete deployment of the bean than have it succeed with a bean that isn't completely deployed.
I have already handled the issue, so I suppose I'm more talking ideology here, but this doesn't seem to be proper behavior. I don't think that clients should be able to remotely lookup incompletely deployed beans.
Anyone else agree, or is this behavior part of the EJB Spec and just needs to be handled?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103311#4103311
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103311
18 years, 8 months
[JBoss Seam] - Some error startup embededjboss, any one can help me?
by coolfish
when i run testcase extends from seamtest,there are errors when startup the embedded jboss:
FAILED CONFIGURATION: @BeforeClass init
java.lang.RuntimeException: Unable to bootstrap:
at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:167)
at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:201)
at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:214)
at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:11)
at org.jboss.seam.mock.BaseSeamTest.startJbossEmbeddedIfNecessary(BaseSeamTest.java:1017)
at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:942)
at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
Caused by: org.jboss.kernel.spi.registry.KernelRegistryEntryNotFoundException: Entry not found with name: MainDeployer
at org.jboss.kernel.plugins.registry.AbstractKernelRegistry.getEntry(AbstractKernelRegistry.java:89)
at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:163)
... 28 more
... Removed 22 stack frames
========================================
how to resovle this?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103309#4103309
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103309
18 years, 8 months