Please, i have some problems with my web application.
I can't paste my code here ( too big and i have the difficulty to reproduce the error ) but, this is my issus.
I have a object that contains a collection. I use BlockquingQueue to share this objet betwen some thread. the second kind of thread is a servlet.
When i put my objet in the queue, the collection is not empty and i can display thier element.
But, when i take the same element, the collection size is not null, but it don't have elements.
NB: I don't have problems to get the objet in queue. My problems it which their attribute of type Collection
. It show me a strange behavoir.
a big part of a code:
public class HttpCollectionConsumer extends JCasAnnotator_ImplBase{
private static BlockingQueue<Answer> queue = new LinkedBlockingQueue<>();
private static boolean hasNext = true;
public void initialize(UimaContext context) throws ResourceInitializationException{
super.initialize(context);
}
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
// TODO Auto-generated method stub
edu.cmu.lti.oaqa.type.input.Question q = TypeUtil.getQuestion(jcas);
System.out.println("get Text " + q.getText());
Question question = new Question(q.getId() , q.getText());
Focus focus = TypeUtil.getFocus(jcas);
Collection<LexicalAnswerType> types = TypeUtil.getLexicalAnswerTypes(jcas);
Answer a = new Answer();
a.setQuestion(question);
a.setFocus(focus);
a.setTypes(types);
try {
System.out.println("identifiant : ( " + a + " ) types " + a.getTypes().iterator().next());
System.out.println("the answer type is not empty : " + a.getTypes().iterator().hasNext());
synchronized(this){
queue.put(a);
Thread.sleep(1000);
}
System.out.println("putting finished " );
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static synchronized void put(Answer question) throws InterruptedException{
System.out.println("new answer : " + question);
queue.offer(question);
}
public synchronized static Answer take() throws InterruptedException{
Answer a = queue.take();
Thread.sleep(2000);
System.out.println(" someone takess ( " + a + " ) , remaining: " + queue.size());
System.out.println("the answer type is not empty : " + a.getTypes().iterator().hasNext());
return a;
}
public synchronized static BlockingQueue<Answer> getQueue(){
return queue;
}
public synchronized static void stop(){
hasNext = false;
}
}
Someone can know why ?