Running JMS simple application from java standalone program stucks

Hi All, i`m new to JMS service, and tried to code a simple application from the J2EE guide. They use standalone j2ee client application there, and i did not
dound any way to debug it from eclipse .. so i have coded following standalone app (not j2ee client JAR) to produce simple messages
public class producerMain {
     public static void main(String argv[]) throws NamingException, JMSException
          Properties jndiProp = new Properties();
          jndiProp.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
          jndiProp.put(javax.naming.Context.PROVIDER_URL, "localhost:3920");
          InitialContext context =new InitialContext(jndiProp);
          ConnectionFactory factory = (ConnectionFactory)context.lookup("sashaConnectionFactory");
          Queue queue = (Queue)context.lookup("jms/Queue");
          System.out.println("Got here");
          Connection connection = factory.createConnection();
Session session = connection.createSession(
false,
Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage();
for (int i = 0; i < 5; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " + message.getText());
producer.send(message);
producer.send(session.createMessage());
producer.close();
session.close();
connection.close();
factory = null;
     context.close();
     System.out.println("Quiting application");
application works .. it sends a messages .. but it does not quit .. (dozens of new threads get opened, besides the main thread, which quits, but other threads
does not quit .. and the application stucks .. )
Does anyone know, why does it stuck .. what are those threads ? and why does not they finish ?
Thanks, Regards Sasha.

Thanks.
changing to
exp.append("\n");and flushing the writer stream and closing the stream fixed the problem.
Why do we have to flush the stream?
and, why do we have to close the writer before reading? what if I want to continue writting in to the writer?
thanks again.

Similar Messages

  • Running a Linux application from Java

    Hy,
    I am working at a faculty project and I need your help
    What I want to do is by clicking a button, in a JFrame I want to open an application ,for example Mysql Query browser. I am using FC 6 and Netbeans 5.5
    Can you help me??
    Thanks

    can I open the konsole from java??Yes.
    First you must figure out how to do that from the command line yourself. That has nothing to do with java.
    Note that that how you do that MUST account for the fact that the "command line" is actually a shell. Some commands must be run by running the shell as the actual command and then passing the desired command as an option to the shell (the actual command.)
    Again you can google for examples.

  • How to run a remote application (Non Java) from a Java program

    Could you please tell me how to run a remote application (Non-Java) from a Java program without using RMI. Please tell me know the procedure and classes to be used.
    Cheers
    Ram

    what do you mean remote application.In the other pc or in your pc just apart from you application?
    If the application is in your pc,the method which the upper has mentioned is
    a good one!
    But if the application you want to run is not in your computer,the method can't do. And you can use socket with which you can build an application listening some port in the pc which contains the application you want to run .When you want to run that application ,send the Start_Command to the listening application.Then listening application will run the application with the help of the method the upper mentioned.

  • Close a running application from java........

    Hi all
    I have opened an application say MSWORD from my java class using Runtime.getRuntime(), Now on close button i need to close the application and on the save button of the application i even want to save the application from java command
    The question is HOW????
    please reply,
    Thanx,
    Amitt

    can I open the konsole from java??Yes.
    First you must figure out how to do that from the command line yourself. That has nothing to do with java.
    Note that that how you do that MUST account for the fact that the "command line" is actually a shell. Some commands must be run by running the shell as the actual command and then passing the desired command as an option to the shell (the actual command.)
    Again you can google for examples.

  • Need to call OAF API from JAVA concurrent program

    Hi Gurus,
    I am trying invoke an OAF Application method which generate the Batch ID. I am trying the invoke the same from JAVA Concurrent program. Below is teh code used,
    package oracle.apps.ego.item.cp;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import oracle.apps.ego.item.common.server.EgoBatchHeader;
    import oracle.apps.ego.item.itemimport.server.EgoImportBatchHeaderAMImpl;
    import oracle.apps.fnd.cp.request.CpContext;
    import oracle.apps.fnd.cp.request.JavaConcurrentProgram;
    import oracle.apps.fnd.cp.request.LogFile;
    import oracle.apps.fnd.cp.request.OutFile;
    import oracle.apps.fnd.cp.request.ReqCompletion;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.ApplicationModuleCreateException;
    import oracle.jbo.ApplicationModuleHome;
    import oracle.jbo.JboContext;
    import oracle.jbo.domain.Number;
    import oracle.jdbc.internal.OracleCallableStatement;
    public class XX_EGO_BATCH_CREATE implements JavaConcurrentProgram {
    static LogFile log = null;
    public void runProgram(CpContext ctx){
    //Obtain the reference to the Output file for Concurrent Prog
    OutFile out = ctx.getOutFile();
    EgoBatchHeader v_header = new EgoBatchHeader();
    //Obtain the reference to the Log file for Concurrent Prog
    log = ctx.getLogFile();
    log.writeln("Batch Number Creation", 0);
    ApplicationModule am = null;
    try{
    //Write your logic here
    log.writeln("Batch Number Creation", 0);
    log.writeln("definition of batch num",0);
    Number batch_num;
    Number ssid = new Number(10000);
    String jdbcUrl =
    "jdbc:oracle:thin:apps/[email protected]:10201:ARERP4";
    ApplicationModule am_Member = null;
    log.writeln("Before Calling Create method",0);
    am_Member =
    create("oracle.apps.ego.item.itemimport.server.EgoImportBatchHeaderAMImpl",
    jdbcUrl);
    log.writeln("assigning ssid"+ssid,0);
    EgoImportBatchHeaderAMImpl bheader = new EgoImportBatchHeaderAMImpl();
    log.writeln("bheader object is :"+bheader,0);
    log.writeln("calling getBatchObjectForCreate"+bheader,0);
    v_header = bheader.getBatchObjectForCreate(ssid);
    //System.out.println("v_header is :" + v_head);
    log.writeln("calling createBatch"+v_header,0);
    batch_num = bheader.createBatch(v_header);
    log.writeln("Batch Number is :"+batch_num ,0);
    out.writeln("This will be printed to the Output File");
    log.writeln("This will be printed to the Log File", 0);
    //Request the completion of this Concurrent Prog
    //This step will signal the end of execution of your Concurrent Prog
    ctx.getReqCompletion().setCompletion(ReqCompletion.NORMAL,"Completed.");
    //Handle any exceptional conditions
    catch(Exception e){
    log.writeln("Exception2 occurred here !!"+e,0);
    log.writeln("calling createBatch"+v_header,0);
    public static ApplicationModule create(String amDefName,
    String jdbcConnStr) throws ApplicationModuleCreateException, Exception {
    ApplicationModule am = null;
    try {
    OracleCallableStatement conn = null;
    // Setup the hashtable of JNDI initialization parameters
    log.writeln("inside create method .. ",0);
    Hashtable env = new Hashtable(2);
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    JboContext.JBO_CONTEXT_FACTORY);
    env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
    // Create an JNDI initial context
    Context ic;
    ic = new InitialContext(env);
    // Lookup a home interface (factory) for the AppModule by name
    ApplicationModuleHome home =
    (ApplicationModuleHome)ic.lookup(amDefName);
    if(home==null){
    log.writeln("home is null... .",0);
    }else{
    log.writeln("home is not null"+home,0);
    // Create an instance of the AppModule using the home/factory
    am = home.create();
    if(am!=null){
    log.writeln("am is not null"+am,0);
    }else{
    log.writeln("am is null",0);
    // Connect the application module to the database
    am.getTransaction().connect(jdbcConnStr);
    } catch (NamingException ex) {
    log.writeln("NamingException occurred here !!"+ex.getMessage(),0);
    ex.printStackTrace();
    throw new ApplicationModuleCreateException(ex);
    }catch(Exception ex){
    log.writeln("Exception occurred here !!"+ex.getMessage(),0);
    ex.printStackTrace();
    throw new Exception(ex);
    return am;
    I am not able to call the web server and facing issues. Please let me know if you can help me to get a solution to this.
    Thanks in advance
    Veerendra

    Hi Zafar,
    I got an error saying :
    Batch Number Creation
    Batch Number Creation
    definition of batch num
    Before Calling Create method
    inside create method ..
    home is not nulloracle.jbo.server.ApplicationModuleHomeImpl@11d2572
    Jul 9, 2008 5:04:21 AM oracle.adf.share.config.ADFConfigFactory findOrCreateADFConfig
    INFO: oracle.adf.share.config.ADFConfigFactory No META-INF/adf-config.xml found
    Exception occurred here !!JBO-25002: Definition oracle.apps.ego.item.itemimport.server.EgoImportBatchHeaderAMImpl of type ApplicationModule not found
    oracle.jbo.NoDefException: JBO-25002: Definition oracle.apps.ego.item.itemimport.server.EgoImportBatchHeaderAMImpl of type ApplicationModule not found
         at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:441)
         at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:358)
         at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:340)
         at oracle.jbo.server.MetaObjectManager.findMetaObject(MetaObjectManager.java:700)
         at oracle.jbo.server.ApplicationModuleDefImpl.findDefObject(ApplicationModuleDefImpl.java:232)
         at oracle.jbo.server.ApplicationModuleImpl.createRootApplicationModule(ApplicationModuleImpl.java:401)
         at oracle.jbo.server.ApplicationModuleHomeImpl.create(ApplicationModuleHomeImpl.java:91)
         at oracle.apps.ego.item.cp.XX_EGO_BATCH_CREATE.create(XX_EGO_BATCH_CREATE.java:139)
         at oracle.apps.ego.item.cp.XX_EGO_BATCH_CREATE.runProgram(XX_EGO_BATCH_CREATE.java:57)
         at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
    Exception2 occurred here !!java.lang.Exception: oracle.jbo.NoDefException: JBO-25002: Definition oracle.apps.ego.item.itemimport.server.EgoImportBatchHeaderAMImpl of type ApplicationModule not found
    calling [email protected]9c

  • How to call a VB application from Java

    Hi,
    does anybody know how to call a VB application from java.
    Would appreciate if you can provide me with an example.
    thanks

    try exec()ing the cad program with the name of the file as a command line parameter...
    Runtime.getRuntime().exec("CADProg.exe Test.prt");
    i have no clue if this will work but it seems like it's worth a try.

  • Running a jar file from java code

    Hi!
    Im trying to run a jar file from my code.
    I've tried Classloader, but that doesnt work because it doesnt find the images (also embedded in the 2nd jar file).
    WHat I would like to do is actually RUN the 2nd jar file from the first jar file. There must be a way to do this right?
    any ideas?

    ok, I found some wonderful code (see below) that will try to start the jar. But it doesn't. What it does is produce the following error when my application runs...
    So it's not finding the images in the jar file that I am trying to run? Strange. I checked the URL that sending, but it seems ok....
    I think I will check the url again to make sure......
    any ideas?
    Uncaught error fetching image:
    java.lang.NullPointerException
         at sun.awt.image.URLImageSource.getConnection(Unknown Source)
         at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
         at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
         at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
         at sun.awt.image.ImageFetcher.run(Unknown Source)
    the code....
    /* From http://java.sun.com/docs/books/tutorial/index.html */
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.net.JarURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.jar.Attributes;
    * Runs a jar application from any url. Usage is 'java JarRunner url [args..]'
    * where url is the url of the jar file and args is optional arguments to be
    * passed to the application's main method.
    public class JarRunner {
      public static void main(String[] args) {
        URL url = null;
        try {
          url = new URL(args[0]);//"VideoTagger.jar");
        } catch (MalformedURLException e) {
          System.out.println("Invalid URL: ");
        // Create the class loader for the application jar file
        JarClassLoader cl = new JarClassLoader(url);
        // Get the application's main class name
        String name = null;
        try {
          name = cl.getMainClassName();
        } catch (IOException e) {
          System.err.println("I/O error while loading JAR file:");
          e.printStackTrace();
          System.exit(1);
        if (name == null) {
          fatal("Specified jar file does not contain a 'Main-Class'"
              + " manifest attribute");
        // Get arguments for the application
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        // Invoke application's main class
        try {
          cl.invokeClass(name, newArgs);
        } catch (ClassNotFoundException e) {
          fatal("Class not found: " + name);
        } catch (NoSuchMethodException e) {
          fatal("Class does not define a 'main' method: " + name);
        } catch (InvocationTargetException e) {
          e.getTargetException().printStackTrace();
          System.exit(1);
      private static void fatal(String s) {
        System.err.println(s);
        System.exit(1);
    * A class loader for loading jar files, both local and remote.
    class JarClassLoader extends URLClassLoader {
      private URL url;
       * Creates a new JarClassLoader for the specified url.
       * @param url
       *            the url of the jar file
      public JarClassLoader(URL url) {
        super(new URL[] { url });
        this.url = url;
       * Returns the name of the jar file main class, or null if no "Main-Class"
       * manifest attributes was defined.
      public String getMainClassName() throws IOException {
        URL u = new URL("jar", "", url + "!/");
        JarURLConnection uc = (JarURLConnection) u.openConnection();
        Attributes attr = uc.getMainAttributes();
        return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
       * Invokes the application in this jar file given the name of the main class
       * and an array of arguments. The class must define a static method "main"
       * which takes an array of String arguemtns and is of return type "void".
       * @param name
       *            the name of the main class
       * @param args
       *            the arguments for the application
       * @exception ClassNotFoundException
       *                if the specified class could not be found
       * @exception NoSuchMethodException
       *                if the specified class does not contain a "main" method
       * @exception InvocationTargetException
       *                if the application raised an exception
      public void invokeClass(String name, String[] args)
          throws ClassNotFoundException, NoSuchMethodException,
          InvocationTargetException {
        Class c = loadClass(name);
        Method m = c.getMethod("main", new Class[] { args.getClass() });
        m.setAccessible(true);
        int mods = m.getModifiers();
        if (m.getReturnType() != void.class || !Modifier.isStatic(mods)
            || !Modifier.isPublic(mods)) {
          throw new NoSuchMethodException("main");
        try {
          m.invoke(null, new Object[] { args });
        } catch (IllegalAccessException e) {
          // This should not happen, as we have disabled access checks
    }

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • How can i get the source code from java concurrent program in R12

    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    Zulqarnain

    user570667 wrote:
    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Launching applications from java code

    I have found a solution to launch applications from java.I thought this will be useful for programmers who want to open a
    1. Browser
    2. Player
    3. Files etc.
    There are 2 solutions :
    I)To use a known application :
    eg: to open windows media player
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe";
    cmd[1] = "/C";
    cmd[2] = "START MPLAYER2.exe "+mediaURL+" /PLAY /CLOSE /FULLSCREEN";
    //eg: mediaURL = "\"D:/project/songs/track1.mp3\""
    // /PLAY /CLOSE /FULLSCREEN this option can be used only for windows media player
    // for any other application use cmd[2] as START apl.exe //apl can be any windows application
    Process p = Runtime.getRuntime().exec(cmd);
    II) To use a default application:
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
    // url can be any url
    ref: [http://forums.sun.com/thread.jspa?threadID=5203313|http://forums.sun.com/thread.jspa?threadID=5203313]
    [http://www.ericphelps.com/batch/rundll/|http://www.ericphelps.com/batch/rundll/]
    Edited by: veda_sishta on ? ?????, ???? ??:?? ???????
    Edited by: veda_sishta on ? ?????, ???? ??:?? ???????

    To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    And make up your mind what file type you're having a problem with. Maybe .asx doesn't have a file association on your computer.
    This works just fine for .m3u:import java.awt.Desktop;
    import java.io.File;
    import java.io.IOException;
    public class Playlist {
       public static void main(String[] args) {
          try {
             Desktop.getDesktop().
                   open(new File("E:/Music/Playlists/test.m3u"));
          } catch (IOException ex) {
             ex.printStackTrace();
    }db
    edit Did you try searching the net for the error you got? ("Invalid menu handle")
    Edited by: Darryl.Burke

  • How do I start and suspend Java Application from say C++ program

    I want to start a Java application via C++ and on some condition i want to suspend the same program not terminate , but suspend

    Have you tried running the virtual machine from your C++ application ? You can start Java applications from your C++ application using JNI after starting the Virtual machine from within your C++ application. According to the Java documentation you can even now stop the virtual machine from within your C++ program.
    I haven't looked at the 'suspend' detail but I suppose it will not be a problem to call a method via JNI to set a flag to suspend a thread etc.
    There is a tutorial: 'Invoking the Java Virtual Machine' at the following URL: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html.
    This example seems to work only for version1.1 of the JDK. For JDK1.3, version 1.2, (I am not so sure whether I fully understand Sun's version numbers for Java yet) there is some updates on the JNI for starting the VM from C++. This article is called 'JNI Enhancements'. The URL for this article is:
    http://java.sun.com/j2se/1.3.0/docs/guide/jni/jni-12.html
    You have to set version to: JNI_VERSION_1_2
    There is only one problem. I get an error when calling JNI_CreateJavaVM from C++. I could not find any documentation that indicates how you can go about diagnosing what is causing the problem. Normally in Visual C++ you can just get the probable cause by inspecting GetLastError() or the function itself can return helpful diagnostic (error) codes.
    If you manage to start the VM correctly from within Visual C++ please let me know. My email address is [email protected]
    good luck
    Henko

  • How to run Other application from Java

    I want to run other applications such as IE.exe, notepad.exe from Java? How can I run?

    Dear Friend, the following is the code to open IExplorer from Java Program
    class RunTimeTest {
    public static void main(String args[]) {
    try {
    Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
    catch(Exception e) {
    [\code]
    ALL THE BEST
    Shiva                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Run dial-up connection from Java Program?

    Is there a way to run dial-up connection from a Java Program? It needs to platform independent.
    Thanks.
    Virum

    I very much doubt it, at least not platform independent. I had a, oops, heck of a time doing that from Visual Basic, where it is much easier to work with operating-system stuff like that than it is in Java. I finally ended up buying a RAS component to call from my VB program.

  • How to run another concurrent from Java Concurrent Program?

    Hi,
    I have one Java Concurrent Program in ebs R12.
    I need to run another Java Concurrent Program when first finished.
    I can not find a way to start another request from JCP.
    Thanks,
    ms

    Hi ,
    this is an example code to check the OS before running the command :
    try{
    int ch;
    Process proc ;
    Runtime r=Runtime.getRuntime();
    StringBuffer sbuf = new StringBuffer();
    String dir = new String();
    String osname = System.getProperty("os.name");
    if(osname.equals("Windows NT") )
    proc = r.exec("cmd /c dir");
    if(osname.startsWith("Linux") )
    proc = r.exec("df -k");
    InputStream is = proc.getInputStream();
    while((ch=is.read() ) != -1)
    sbuf.append((char)ch);
    is.close();
    dir = sbuf.toString();
    System.out.println(dir );
    }catch(Exception e){ System.out.println(e.getMessage());}
    bye
    Taha

  • How to call msword application from java program

    hai every body
    i want to know about OLE in java.
    how can i invoke msoffice application in java code.
    if any body have sanple code for this post for me
    thank you

    There are some bridges available ...
    http://www.google.com/search?q=ole+java+bridge

Maybe you are looking for