ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Mixed threads how is it possible ??

Post new topic  Reply to topic
 Mixed threads how is it possible ?? « View previous topic :: View next topic » 
Author Message
ramires
PostPosted: Thu May 30, 2002 6:07 am    Post subject: Mixed threads how is it possible ?? Reply with quote

Knight

Joined: 24 Jun 2001
Posts: 523
Location: Portugal - Lisboa

Hi,
I have a servlet that receives a request from a browser, creates a dynamic queue, puts a msg to a remote q (with replyq = to dynamic q name) and goes to a getwait for some seconds.
It runs ok, but...
When two users in a browser call the servlet athe same time, te impossible happens, I see the to servlets starting but the second one takes control on both requests:
The output from the web server
As you can see, two intances were started, one at 1022766857956 and
another at 1022766858076 (time miliseconds). And this last one takes control !
Any suggestions ??

Thanks , Joao

1022766857956 DBG run SERVLET started at 1022766857956
1022766857956 DBG a conectar a QMgr: TMQSERIES
1022766858076 DBG run SERVLET started at 1022766858076
1022766858076 DBG a conectar a QMgr: TMQSERIES
1022766858076 DBG a fazer o open da Queue de Send
1022766858076 DBG mensagem recebida
1022766858076 DBG a fazer o open da Queue de Send
1022766858076 DBG mensagem recebida
1022766858076 DBG criada Q Dinamica TRQPRTSIN3CF60BF100041042
1022766858076 DBG criada Q Dinamica TRQPRTSIN3CF60BF100042012
1022766858076 DBG Enviou mensagem
1022766858076 DBG Q dinamica e : TRQPRTSIN3CF60BF100042012
1022766858076 DBG Enviou mensagem
1022766858076 DBG Q dinamica e : TRQPRTSIN3CF60BF100042012
1022766858076 DBG MQ error em GET : CC 2 RC 2019
1022766858076 DBG fez o get da mensagem !!!
1022766858076 DBG foi devolvida a mensagem , lida da Q Dinamica
Back to top
View user's profile Send private message
kolban
PostPosted: Thu May 30, 2002 6:14 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

Hmmm ... as you say, a dynamically created queue must/should be unique amongst all the queues on the queue manager. If this is not happening, we have a very, very serious problem here. Would it be possible to post the code of the servlet associated with the queueing?
Back to top
View user's profile Send private message
ramires
PostPosted: Thu May 30, 2002 6:32 am    Post subject: Reply with quote

Knight

Joined: 24 Jun 2001
Posts: 523
Location: Portugal - Lisboa

The code, with lot of prints to debug. A client connection is used, and can say I had to see it belive it.

//////////////////////////////////////////
//
// Mudanças em 03/05/2002
// Inclusão de um destroy method
// Inclusão de um closure da mqueue1
// Inclusão de alguns comentários
//
//////////////////////////////////////////

//////////////////////////////////////////
//
// To do
// Averiguar o resultado das alterações
// Averiguar algumas variáveis que não parecem ser usadas
// Averiguar a mudança para a tag CDATA
// Averiguar as opções que estão a ser usadas para o acesso às Qs e
// verificar se são os mais apropriados
// Várias contact admin observações/análises
//
//////////////////////////////////////////


// Imports

import com.ibm.mq.*;
//import java.io.IOException;
//import java.io.FileInputStream;
//import java.io.PrintStream;
//import java.io.DataInputStream;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class SMQMess extends HttpServlet {


// Declaração de Private Variables

private static String qManager;
private static String qName;
private String qNameTeste;
private int qWait;
private String msgText;
//private String msgInText; // Mensagem que vem como parâmetro do HTML
private String QueueTemplate = "SYSTEM.DEFAULT.MODEL.QUEUE"; // Q que vai servir de template para as Qs dinâmicas
private MQQueueManager qMgr; // Q Manager
private MQGetMessageOptions gmo=null; // Options de GetMessage
private MQMessage getmsg=null; // Mensagem a receber
private int openOptions; // Opcoes de accessQueue (Open)
private static MQQueue mqQueueSend;
private MQQueue mqQueueDinamica;// = new MQQueue();
private MQQueue mqQueueReply;// = new MQQueue();
private MQMessage mqmessage = null;

private String strTime;
private long intstrTime;
private FileOutputStream traceFile;


/**
* Insert the method's description here.
* Creation date: (5/21/2002 5:06:15 PM)
* @return java.lang.String
*/
public static String decod(String arg) {


int iPos=arg.indexOf('=');
arg=arg.substring(iPos+1);
return arg;
}

// HF - 27052002, método decodeQName
// Metodo de decode da Q a enviar baseado no standard de Qs separadas por tipo de mensagem

public String decodeQName(String decodeMsg) {

return ("MQ1P.INPUT.RPTZ." + (decodeMsg.substring(13,17)));

}

// Método Destroy - chamado quanto a servlet é destruída

public void destroy() {

try {

//Disconnect from the queue manager
// Close da Q de Send
mqQueueSend.close();
qMgr.disconnect();

}
catch (MQException ex) {
System.out.println("An MQ error occourred: Completion code " + ex.completionCode + " Reason code" + ex.reasonCode);
}
}

// Método doGet - resposta ao pedido via doGet

public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws IOException {


intstrTime = System.currentTimeMillis();
strTime = (java.lang.String.valueOf(intstrTime));
System.out.println(strTime +" DBG run SERVLET started at "+ strTime);
qManager = "TMQSERIES";

//System.out.println(strTime + qMgr.isConnected());

try {

System.out.println(strTime + "DBG a conectar a QMgr: " + qManager);
qMgr = new MQQueueManager(qManager);

qMgr.commit();


openOptions = MQC.MQOO_OUTPUT;
mqQueueSend = qMgr.accessQueue(qName, openOptions);
System.out.println(strTime + "DBG a fazer o open da Queue de Send");
}
catch(MQException mqexception) {
System.out.println("Erro ao conectar QMgr: Completion Code : "+ mqexception.completionCode + ",Reason Code :" + mqexception.reasonCode);
}


//*******************************************************
try {

traceFile = new FileOutputStream("c:\\trc\\app"+strTime+".trc");
MQEnvironment.enableTracing(3,traceFile);
}
catch (IOException ex) {
// couldn't open the file,
// trace to System.err instead
MQEnvironment.enableTracing(2);
}


// HttpSession sessao=httpservletrequest.getSession(true);

httpservletresponse.setContentType("text/html");
ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
String msgInText = httpservletrequest.getParameter("InMsg");
if(msgInText.equals("") | (msgInText == null)) {
System.out.println("No Input Message");
System.exit(1);
}
else
{

//System.out.println("\n Mensagem " + msgInText + ", com o tamanho " + msgInText.length());
System.out.println(strTime +" DBG mensagem recebida");
}
try {


openOptions = MQC.MQOO_INPUT_EXCLUSIVE;
mqQueueDinamica = qMgr.accessQueue(QueueTemplate, openOptions, qManager, "TRQPRTSIN*", null);
MQMessage mqmessage = new MQMessage();
mqmessage.format = "MQSTR ";
mqmessage.replyToQueueName = mqQueueDinamica.name;
mqmessage.messageType = MQC.MQMT_REQUEST;
mqmessage.characterSet = 1252;
System.out.println(strTime + " DBG criada Q Dinamica " + mqQueueDinamica.name);

//*************************************


//} catch (Throwable mqexception) {
// System.out.println("Erro na parte 1");
//}

// debugar

try {
mqmessage.writeString(msgInText);
} catch(IOException _ex) {
System.out.println("Erro IO na escrita");
}

MQPutMessageOptions mqputmessageoptions = new MQPutMessageOptions();

try {
//System.out.println("\n A mensagem vai ser colocada na SendQueue com os seguintes dados");
//System.out.println("\n Mensagem da Sessao : " + msgInText + ", com o tamanho " + msgInText.length() + ", e Q Dinamica de resposta " + mqQueueDinamica.name);
mqQueueSend.put(mqmessage, mqputmessageoptions);
System.out.println(strTime + " DBG Enviou mensagem");
}
catch(MQException mqexception1) {
System.out.println("An MQ error occurred : Completion code " + mqexception1.completionCode + " Reason code " + mqexception1.reasonCode);
}

// debugar
try {
//mqQueueSend.close();
openOptions = MQC.MQOO_INPUT_EXCLUSIVE;

// System.out.println("Vai aceder à Q dinamica para tirar o nome da Q !!!");
// Possivel sitio do ERRO abaixo
// DBG 2905 mqQueueReply = qMgr.accessQueue(mqQueueDinamica.name, openOptions);

System.out.println(strTime + " DBG Q dinamica e : " + mqQueueDinamica.name + ", e a de Reply é : " + mqQueueDinamica.name );

//*************************************
//* DBG 29022002

try {

getmsg = new MQMessage();
gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = qWait; // qWait lido de SMQMess.config");
mqQueueDinamica.get(getmsg, gmo, 30000);
mqQueueDinamica.close();
mqQueueSend.close();
qMgr.disconnect();

}
catch(MQException mqexception9) {
System.out.println(strTime + " DBG MQ error em GET : CC " + mqexception9.completionCode + " RC " + mqexception9.reasonCode);
}

//* DBG 29022002
//*************************************

System.out.println(strTime + " DBG fez o get da mensagem !!!");

}

catch (Throwable mqexception) {
System.out.println(strTime + " DBG erro na parte 2 e a excepcao e ");
mqexception.printStackTrace();
}

//debugar
//try {
// mqQueueReply.close();
// mqQueueDinamica.close();
//} catch (MQException mqe) {
// System.out.println("Erro no closing das Qs : Completion Code "+ mqe.completionCode + ",Reason Code" + mqe.reasonCode);
//}

try {
msgText = getmsg.readLine();
System.out.println(strTime + " DBG foi devolvida a mensagem " + msgText + ", lida da Q Dinamica " + mqQueueDinamica.name);
servletoutputstream.println("<HTML>");
servletoutputstream.println("<BODY>");
servletoutputstream.println("<PRE>");
servletoutputstream.println(msgText);
servletoutputstream.println("</PRE>");
servletoutputstream.println("</BODY>");
servletoutputstream.println("</HTML>");

traceFile.close();

return;
}
catch(IOException _ex) {
System.out.println("error getting reply...");
}
return;

}

catch(MQException mqexception) {
servletoutputstream.print(mqexception.reasonCode);
System.out.println("Catch final : MQ exception: " + mqexception.exceptionSource + " CC = " + mqexception.completionCode + " RC = " + mqexception.reasonCode);
return;
}
}


// ****************************************************************
// Método Init - chamado quanto a servlet é iniciada (instanciada)
// ****************************************************************

public void init(ServletConfig servletconfig) {

try {

FileInputStream fileStream = new FileInputStream("c:\\MQconfig\\SMQMess.config");
DataInputStream di = new DataInputStream(fileStream);
String linha=di.readLine();
while (linha!=null) {
if (linha.startsWith("HOSTNAME"))
MQEnvironment.hostname = decod(linha);
if (linha.startsWith("CHANNEL"))
MQEnvironment.channel = decod(linha);
if (linha.startsWith("QMANAGER"))
qManager = decod(linha);
if (linha.startsWith("QNAME"))
qName = decod(linha);
if (linha.startsWith("QWAIT"))
qWait = new Integer(decod(linha)).intValue();
linha = di.readLine();
}
di.close();
fileStream.close();
}

catch (java.io.FileNotFoundException e) {
System.out.println("Ficheiro de Configuração não foi encontrado");
System.out.println(e.toString());

}

catch (java.io.IOException e) {
System.out.println(e.toString());
}

// try {
// qMgr = new MQQueueManager(qManager);
// System.out.println("A conectar a QMgr: " + qManager);
// openOptions = MQC.MQOO_OUTPUT;
// mqQueueSend = qMgr.accessQueue(qName, openOptions);
// System.out.println("A fazer o open da Queue de Send");
// return;
// }
// catch(MQException mqexception) {
// System.out.println("Erro ao conectar QMgr: Completion Code : "+ mqexception.completionCode + ",Reason Code :" + mqexception.reasonCode);
// }

// System.exit(0);
}
}
Back to top
View user's profile Send private message
ramires
PostPosted: Sun Jun 02, 2002 12:25 pm    Post subject: Reply with quote

Knight

Joined: 24 Jun 2001
Posts: 523
Location: Portugal - Lisboa

my problem is solved! in fact it was due to bad java coding and not MQ. Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Mixed threads how is it possible ??
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.