Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Inspired by this question this question, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I have a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

I want to ask if this code is good.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus around here shun on the use of synchronized in an EE context.

I found this (in German), which also explains that synchronized is not allowed in EJB.

Inspired by this question, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I have a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

I want to ask if this code is good.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus around here shun on the use of synchronized in an EE context.

I found this (in German), which also explains that synchronized is not allowed in EJB.

Inspired by this question, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I have a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

I want to ask if this code is good.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus around here shun on the use of synchronized in an EE context.

I found this (in German), which also explains that synchronized is not allowed in EJB.

edited tags; edited title
Link
200_success
  • 145.5k
  • 22
  • 190
  • 479

Synchronization in Querying a list of jobs on a server using EJBs

added 28 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Inspired by Handling messages from a serverthis question I want to ask if this code is good.

, I have ana Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I havahave a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

I want to ask if this code is good.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus aorundaround here shun on the use of synchronized in an EE context.

EDIT: I I found this this(in germanGerman): http://blog.holisticon.de/2010/11/synchronisation-und-nebenlaufigkeitskontrolle-mit-ejbs-leicht-gemacht/ , which also explains that synchronized is not allowed in EJB.

Inspired by Handling messages from a server I want to ask if this code is good.

I have an Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I hava a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus aorund here shun on the use of synchronized in an EE context.

EDIT: I found this (in german): http://blog.holisticon.de/2010/11/synchronisation-und-nebenlaufigkeitskontrolle-mit-ejbs-leicht-gemacht/ which also explains that synchronized is not allowed in EJB.

Inspired by this question , I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.

For this I have a bean that maintains a collection of jobs that is set by the server and the client then asks if his job is in the current list of jobs known to the bean.

I want to ask if this code is good.

The client uses this interface:

import javax.ejb.Remote;
@Remote
public interface GeneratorCancelledRemote {
 public boolean isJobCancelled(String jobId);
}

The server uses this interface:

import java.util.Collection;
import javax.ejb.Local;
@Local
public interface GeneratorCancelledLocal {
 public void setJobs(final Collection<String> jobs);
}

And here's the implementation:

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import javax.ejb.Stateless;
@Stateless
public class GeneratorCancelled implements GeneratorCancelledLocal, GeneratorCancelledRemote {
 private Collection<String> jobs;
 public void setJobs(final Collection<String> jobs) {
 this.jobs = Collections.synchronizedSet(new HashSet<String>());
 this.jobs.addAll(jobs);
 }
 @Override
 public boolean isJobCancelled(final String jobId) {
 return jobs != null && jobs.contains(jobId);
 }
}

Obviously access to the collection of jobs has to be synchronized somehow. Is the use of Collections.synchronizedSet the best way to do this? The EJB gurus around here shun on the use of synchronized in an EE context.

I found this(in German), which also explains that synchronized is not allowed in EJB.

add link
Source Link
Loading
Source Link
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /