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 IndexIBM MQ API Supportabout MQGetMessageOptions and MQQueue.close

Post new topicReply to topic Goto page 1, 2  Next
about MQGetMessageOptions and MQQueue.close View previous topic :: View next topic
Author Message
seraphim119
PostPosted: Tue Dec 05, 2006 11:28 pm Post subject: about MQGetMessageOptions and MQQueue.close Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

hello ,everyone,i meet a problem!
that's when i use ctrl+c to quit the program,the program will in no answer,and the problem looks like die??
is anybody knows kow to resolve it ??? thanks in advance!
this is my code:
package test;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import clint.MQManager;

import com.ibm.mq.MQException;

public class Test {

/**
* @param args
*/
static {
System.out.println("³ÌÐòÆô¶¯ÖÐ... ...");
System.out.print("³ÌÐò³õʼ»¯... ...");
Runtime runtime = Runtime.getRuntime();
Class c = runtime.getClass();
try {
Method m = c
.getMethod("addShutdownHook", new Class[]{Thread.class});
m.invoke(runtime, new Object[]{new Hooks()});
System.out.println(" [ok]");
} catch (NoSuchMethodException nsme) {

} catch (IllegalAccessException iae) {

} catch (InvocationTargetException ite) {

}
}

public static void main(String[] args) {

String s = null;
try {
s = MQManager.MQ_get();
if (s != null)
System.out.println(s);
MQManager.MQ_putS(s);
MQManager.disConnect();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MQException mqe) {
mqe.printStackTrace();
}

}

}

class Hooks extends Thread {
public void run() {
// ÊÍ·ÅMQ
try {
System.out.print("ÊÍ·ÅMQÁ¬½Ó... ...");
MQManager.disConnect();
System.out.println(" [ok]");
} catch (MQException mqe) {
mqe.printStackTrace();
}

System.out.println("Îļþ´«ÊäÓ¦ÓóÌÐòÒªÍ˳öÁË,... ...!");
}

}
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Dec 06, 2006 2:07 am Post subject: Re: about MQGetMessageOptions and MQQueue.close Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The problem is in this line of code
seraphim119 wrote:

s = MQManager.MQ_get();

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Dec 06, 2006 3:46 am Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20697
Location: LI,NY

And I believe a good reread of the Using Java manual might be in order.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
seraphim119
PostPosted: Wed Dec 06, 2006 4:43 am Post subject: Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

but when i disconnect the MQ in the program(don't disconnect MQ by press ctrl+c to quit program),it will work good:
now i give you my code:(i think my code is fine : )
/*Created on 2006-4-1
* @author SerapH.
* QQ:38641071
* Email:konglingpeng@gmail.com
*/
/* mq¹ÜÀíÀà,Ê×ÏȲúÉúMQManagerÀàµÄʵÀý
* È»ºóµ÷ÓÃmanagerIniliazer()·½·¨³õʼ»¯
* MQ_put(String s)½«×Ö·û´®s·ÅÈë¶ÓÁÐÖÐ
* MQ_get()È¡¶ÓÁÐÖеÄÒ»ÌõÐÅÏ¢
*/
package clint;
import java.io.IOException;

import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

public class MQManager {
private static final String MANAGERNAME = "QM43";
private static final String QUEUENAMERECV = "43_1";
private static final String QUEUENAMESEND = "43_2";
private static int recvOpenOptions = MQC.MQOO_INPUT_AS_Q_DEF;
private static int sendOpenOptions = MQC.MQOO_OUTPUT;
private static MQManager mgr = null;
private static MQQueueManager mqqmgr = null;
private static MQQueue queueRecv = null; // ½ÓÊÕÐÅÏ¢¶ÓÁÐ
private static MQQueue queueSend = null; // ·¢ËÍÐÅÏ¢¶ÓÁÐ
private static MQMessage recvMessage = null;
private static MQMessage sendMessage = null;
private static MQGetMessageOptions gmo = null;
private static MQPutMessageOptions pmo = null;

static {
mgr = new MQManager();
try {
mqqmgr = new MQQueueManager(MANAGERNAME, MQC.MQCNO_STANDARD_BINDING);
gmo = new MQGetMessageOptions();

gmo.options = MQC.MQGMO_LOGICAL_ORDER + MQC.MQGMO_FAIL_IF_QUIESCING
+ MQC.MQGMO_WAIT;
//+ MQC.MQGMO_ALL_MSGS_AVAILABLE
// gmo.waitInterval = 100;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
pmo = new MQPutMessageOptions();
// pmo.options=MQC.MQPMO_LOGICAL_ORDER + MQC.MQPMO_SYNCPOINT;
queueSend = mqqmgr.accessQueue(QUEUENAMESEND, sendOpenOptions);
queueRecv = mqqmgr.accessQueue(QUEUENAMERECV, recvOpenOptions);
// System.out.println("zzzzzz");
} catch (MQException mqEx) {
System.out
.println("MQ¶ÓÁгõʼ»¯´íÎó [" + mqEx.getLocalizedMessage() + "]");
System.exit(0);
}
}

public static String MQ_get() throws IOException, MQException // get a
// message
// from
// queue;
{
recvMessage = new MQMessage();
recvMessage.characterSet = 819;
queueRecv.get(recvMessage, gmo);
int flag = recvMessage.messageFlags;
int length = recvMessage.getMessageLength();
byte tmp[] = new byte[length];
recvMessage.readFully(tmp);
String fileContent = new String(tmp);
System.out.println("[" + fileContent + "]");
if (flag == MQC.MQMF_NONE) {
return fileContent;
} else if (flag == MQC.MQMF_SEGMENT) {
return null;
} else if (flag == (MQC.MQMF_SEGMENT | MQC.MQMF_LAST_SEGMENT)) {
return null;
} else {
return null;
}
}

public static void MQ_putS(String s) throws IOException, MQException // put
// a
// message
// to
// queue;
{
byte id[] = "vsiosoft".getBytes();
byte mqbyte[];
mqbyte = s.getBytes();

sendMessage = new MQMessage();
sendMessage.characterSet = 819;
sendMessage.priority = 1;
sendMessage.messageId = id;
sendMessage.write(mqbyte, 0, mqbyte.length);
queueSend.put(sendMessage, pmo);
}

public static void disConnect() throws MQException { // ÊÍ·Å×ÊÔ´

if (mqqmgr != null) {

if (queueSend != null){
queueSend.close();
System.out.println("1111"); //
}

if (queueRecv != null) {
queueRecv.close();
System.out.println("222"); //
}
System.out.println("jjj");
mqqmgr.disconnect();
}
}
}
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Dec 06, 2006 4:53 am Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Yes, your code does exactly what you have written it to do, and how you have written it is exactly what is causing your problem.

Your problem is at
Code:
queueRecv.get(recvMessage, gmo);

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
seraphim119
PostPosted: Wed Dec 06, 2006 5:20 am Post subject: Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

but what's the problem?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Dec 06, 2006 6:04 am Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You have said that your program doesn't respond when you try and cancel it.

I have told you that your program doesn't respond because it is executing the Get call you have coded.

I'd say the problem is that you don't understand the Get call that you have coded.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Wed Dec 06, 2006 6:28 am Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

I am not a JAVA programmer but even I can see what is wrong here.

Hint: The comments are incorrect!
Back to top
View user's profile Send private message
tleichen
PostPosted: Wed Dec 06, 2006 6:56 am Post subject: Reply with quote

Yatiri

Joined: 11 Apr 2005
Posts: 663
Location: Center of the USA

kevinf2349 wrote:
I am not a JAVA programmer but even I can see what is wrong here.

Hint: The comments are incorrect!


seraphim119 wrote:
/* mq¹ÜÀíÀà,Ê×ÏȲúÉúMQManagerÀàµÄʵÀý
* È»ºóµ÷ÓÃmanagerIniliazer()·½·¨³õʼ»¯
* MQ_put(String s)½«×Ö·û´®s·ÅÈë¶ÓÁÐÖÐ
* MQ_get()È¡¶ÓÁÐÖеÄÒ»ÌõÐÅÏ¢
*/
Yeah, real good!
_________________
IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer
Back to top
View user's profile Send private message
seraphim119
PostPosted: Wed Dec 06, 2006 7:33 am Post subject: Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

the comment is my country language,
but the get method working good when i disconnect the MQ in the Test.java at the end instead of ctrl+c to disconnect the MQ
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Dec 06, 2006 7:36 am Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The get method is doing exactly what you have told it to do.

You have told it to do the wrong thing.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Wed Dec 06, 2006 7:49 am Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

Quote:
The get method is doing exactly what you have told it to do.


....and exactly not what the readable comment implies
Back to top
View user's profile Send private message
seraphim119
PostPosted: Wed Dec 06, 2006 10:54 pm Post subject: Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

can you speak pellucidly?if you know what's the reason,why not speak to me directly,,
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Dec 07, 2006 2:39 am Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

This is your problem.

Code:
// gmo.waitInterval = 100;
gmo.waitInterval = MQC.MQWI_UNLIMITED;


But that should have been fairly obvious, and even more obvious with the hints we gave.

In order to be a programmer, you have to know how to read code.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
seraphim119
PostPosted: Thu Dec 07, 2006 4:11 am Post subject: Reply with quote

Acolyte

Joined: 04 Sep 2006
Posts: 57

if i set the gmo.waitInterval = 100,can you exit the program?
my program can't exit too,,,,so that's my puzzle?canyou help me again?
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum IndexIBM MQ API Supportabout MQGetMessageOptions and MQQueue.close
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.