このコードを使用した単純な REST サービスに問題があります。
@GET
@Path("next/{uuid}")
@Produces({"application/xml", "application/json"})
public synchronized Links nextLink(@PathParam("uuid") String uuid) {
Links link = null;
try {
link = super.next();
if (link != null) {
link.setStatusCode(5);
link.setProcessUUID(uuid);
getEntityManager().flush();
Logger.getLogger("Glassfish Rest Service").log(Level.INFO, "Process {0} request url : {1} #id {2} at {3} #", new Object[]{uuid, link.getLinkTxt(), link.getLinkID(), Calendar.getInstance().getTimeInMillis()});
}
} catch (NoResultException ex) {
} catch (IllegalArgumentException ex) {
}
return link;
}
これにより、リンク オブジェクトが提供され、使用済みとしてマークされ (setStatusCode(5))、サービスへの次のアクセスが同じオブジェクトを送信するのを防ぐ必要があります。問題は、Web サービスにアクセスする高速なクライアントが多数ある場合、このクライアントが同じリンク オブジェクトを異なるクライアントに 2 回または 3 回提供することです。どうすればこれを解決できますか??
@NamedQuery(name = "Links.getNext", query = "SELECT l FROM Links l WHERE l.statusCode = 2") を使用した resquest は次のとおりです。
および super.next() メソッド:
public T next() {
javax.persistence.Query q = getEntityManager().createNamedQuery("Links.getNext");
q.setMaxResults(1);
T res = (T) q.getSingleResult();
return res;
}
どうも