I am wondering if this is a good and correct way to write the implementation of two web service methods (get/set methods).The setPerson method can be called from different threads from a pool, so I think the best way is to make the method synchronized. Or is it possible to lock the table when editing to avoid the synchronization on Java?@Overridepublic synchronized void setPerson(Person person) {    EntityManagerFactory emf = Persistence.createEntityManagerFactory(PersonLibPU);                EntityManager em = emf.createEntityManager();     if(!em.getTransaction().isActive()) {       em.getTransaction().begin();    }    try {         em.merge(person);         em.getTransaction().commit();           emf.getCache().evict(Person.class);                        } catch (Exception ex) {         if(em.getTransaction().isActive())            em.getTransaction().rollback();    } finally {        em.close();    }}And here follows the getPerson method. I didn't make it synchronized since it reads from the JPA cache. @Overridepublic Person getPerson(int personId) {    EntityManagerFactory emf = Persistence.createEntityManagerFactory(PersonLibPU);    EntityManager em = emf.createEntityManager();    try {                   return (Person)em.getReference(Person.class, personId);    } catch (javax.persistence.EntityNotFoundException ex) {        return new Person(); // return empty person    } finally {        em.close();    }}
Webservice methods using EclipseLink and database entities
java;synchronization;web services