Making a program "sit and wait"

I've written a program that drops an icon in the system tray and just waits around for the user to do something with it. When I first wrote the program, it would add the icon to the tray, then immediately exit since there weren't any active threads. I remedied the situation by starting a thread that consists solely of:
while (true) {
     Thread.sleep(9999999);
}This does what I want it to, but it seems like there should be a better way of preventing the JVM from exiting automatically. Any ideas?

I just have an ActionListener strapped to the icon...
the user clicks it, and an ActionEvent is fired off.
No additional thread needed as far as I know.Then you have (I suppose) a Swing framework app, which creates threads behind the scenes. Not a Swing developer myself, but normally one creates normal Swing apps with a visible form, and that doesn't terminate until you close the form. If you're creating a "Windows tray icon" thingy, (which of course would only work on Windows), sounds like for one thing you're using the wrong tool for the job (java is for platform independence, not for Windows-specific apps). But if you want to continue down this road, you should research how Swing creates its threads, and maybe you can "tell" it to make the thread that it is creating a non-daemon thread (or if it creates non-daemon threads, tell it to create a daemon thread instead - I don't remember which type does what).

Similar Messages

  • My ipod Touch 4S is no longer able to update applications (They just sit and wait forever).  How do I fix this?

    My iPod Touch 4S is no longer able to update applications (They just sit and wait forever).  How do I fix this?

    restore or reset your ipod. there is a problem with ipods atm so the best you can do is wait if neither restoring or reseting works.

  • Every since the June 22 security update, I get Mozilla Firefox (not responding) at any page I go to. Have to sit and wait several minutes for it to load each page. Getting all kinds of errors in arsing values. Declartion dropped. Etc.

    Warning: Expected declaration but found '*'. Skipped to next declaration.
    Source File: http://support.mozilla.com/media/css/questions-min.css?build=93872dd
    Line: 1
    Warning: Unknown property 'zoom'. Declaration dropped.
    Source File: http://support.mozilla.com/media/css/questions-min.css?build=93872dd
    Line: 1
    Warning: Error in parsing value for 'display'. Declaration dropped.
    Source File: http://support.mozilla.com/en-US/questions/new?product=beta
    Line: 0
    Warning: Unknown property '-moz-opacity'. Declaration dropped.
    Source File: http://support.mozilla.com/en-US/questions/new?product=beta
    Line: 0
    Warning: Error in parsing value for 'background-image'. Declaration dropped.
    Source File: http://support.mozilla.com/en-US/questions/new?product=beta
    Line: 0
    Just a few of the types of errors collected.
    It is getting to be a pain to have to sit and wait until it is responding again. At that point the cursor is locked on to what ever it is sitting over. You have to click on it to release it.
    Anyone have any ideas.

    Glad it is fixed. Thanks for posting back, (even if we are not sure exactly what happened).

  • Pause program code and wait for window deactivation

    I have the following code. I need the frame to show then the code to pause until the frame is deactivated.
    The problem is that the frame is shown but only the backgound and its contents are not shown and since the while loop waits for a deactivation it goes into an endless loop. If I press the X on the frame it still does not close. I am guessing for some reason the compiler goes into the while loop before it completes the above task of showing the frame. Can you help me out with my problem?
    final viewMemRecordsFrame memframe = new viewMemRecordsFrame(ff);
    memframe.show();
    memframe.setLocation(80, 80);
    memframe.addWindowListener(new WindowAdapter()
    public void windowDeactivated(WindowEvent e)
    acctnumber = -1;
    memframe.dispose();
    public void windowActivated(WindowEvent e)
    Object waitObject = new Object();
    Thread waitThread = new Thread();
    waitThread.start();
    while(memframe.isVisible())
    try
    waitThread.sleep(200);
    catch(InterruptedException ie)
    waitThread.stop();
    ried the Thread.sleep(200) I had the same problem as above. The frame above the while loop shows but does not show the contents of the frame so an input can not be entered and the frame cannot be deactivated and it runs into an endless loop.

    You appear to have some confusion about threads. Your waitThread doesn't have any code to run, which means it will terminate as soon as you start it.
    "stop" is now depracated and there's really no need for it.
    I'm guessing that this piece of code is activated by some kind of GUI control, which would accont for your program hanging, since no other GUI control (e.g. the close box) can be serviced until an ActionPerfomed method or similar has finished.
    If you want a thread to wait for a window to close the appropriate syncrhonization methods are wait and notify, not sleep.
    For example override "dispose" in "viewMemrecords with:
    public void dispose() {
        synchronized(this) {   // grab the window as a monitor
              super.dispose();  // call the underlying dispose to close the window
              notifyAll();      // wake any waiting threads
       }Then the thread which is to wait does something like:
    syncrhonized(memframe) {
         while(memframe.isVisible())
              memframe.wait();
          }This should make the WindowListener unecessary.
    But [b[don't[/b] make code executed from an GUI action handler wait. GUI action handlers should always return promptly, creating a new Thread if any continuing action is required.

  • I have been getting firefox not responding for months. It is worse today. I sit and wait and wait. It's not worth it. I have searched about plugins and find nothing that seems to get rid of the problem. Please what can I do about this.

    When I first started with firefox it was great and I was so happy with it. Well I have to say it has gotten so bad today that I am ready to give up. I have run virus scans, malware scans and even disabled a couple of add ons but to no avail its terrible.
    Surely you all know what add ons it could be if thats it at all. Getting pretty desperate here.
    Nancy

    Waka_Flocka_Flame, it looks like you were right. It was an app called "Safe Saver" of all things, that I got with a coupon website. No more magnifying glasses!

  • Send my uptodate program claim and didn't get any reedem code yet..

    I bought from apple retail store in new york new macbook pro 13" in 1st july 2011. I entered to the uptodate program site and did this two days ago and still i don't get any mail with the reedem code to the app store. what i need to do? someone get any code?

    I bought a macbook on July 14th, uptodate didn't recognize my serial so I had to fill the form too... Still waiting for anything back from them. I'm tempted to go to the local apple store.

  • My program stops and i don't know why...

    I am not sure if i have a problem with my code or the VM but I'm assuming it's my code and hoping someone can help. I already searched through the forums and the bug database and I found some things I thought could maybe be my problem but after more testing the fixes and workarounds didn't work...
    It is a middleware between clients and database server all in java.
    The main thread invokes a thread that accepts socket connections and adds them to a connection queue (LinkedList). Various worker threads in a ThreadGroup wait and work with the connections as they come in. All this works correctly. Unfortunately my app is now displaying the unwanted characteristic of coming to an abrupt stop (not shutting down correctly) in an erratic manner. If no clients ever connect the app will sit and wait just fine (over 30 hours in 1 test until I stopped it) as soon as one connection is made however the app appears to be doomed. It will just stop anywhere between instantly and 10 minutes after the last connection is closed. Usually the span is between 2 and 3 minutes but it varies widely. It also will stay alive if another client connects, basically if the server is busy things are fine but when it is twiddling its thumbs waiting it just halts.
    Here is what the orginal code looks like...
    while(qOpen){
      Socket s = null;
      try{
        s = ss.accept();
      }catch(IOException clientConnectError){
        continue;     
      try{
        rq.addConnection(s);
      }catch(ConnectionQueueException closed){
        // if the queue is closed attempt to close the socket either way set our flag to closed so we exit the loop
        try{
          s.close();
        }catch(IOException clientCloseError){}     
        qOpen = false;          
    // the next line does not show up when the server stops
    System.out.println("Server Shutting down...");i thought maybe my code was doing something bad somewhere and I had an uncaught exception or error such as outofmemory. So I altered the code slightly to trap any errors or exceptions that were possibly coming down so I would know where to debug.
    Altered code
    while(qOpen){
      try{
      Socket s = null;
      try{
        s = ss.accept();
      }catch(IOException clientConnectError){
        continue;     
      try{
        rq.addConnection(s);
      }catch(ConnectionQueueException closed){
        // if the queue is closed attempt to close the socket either way set our flag to closed so we exit the loop
        try{
          s.close();
        }catch(IOException clientCloseError){}     
        qOpen = false;          
      }catch(Throwable thrown){thrown.printStackTrace();}
    // the next line does not show up when the server stops
    System.out.println("Server Shutting down...");The server stops and prints out nothing.
    Finally I thought maybe something bad is happening to the thread group. So I added another thread that loops and prints out some information about the ThreadGroup....
    Thread Group Information
    Active Count : 8
    Is Daemon : false
    This prints out like this exactly the same each time including the iteration just before everything comes to a halt.
    So I am stuck, (1)the app is not shutting down properly, (2)I cannot find (or trap) an error that is causing it to stop and (3) nothing wierd seems to be happening to my group of workers. What else can I do to find this error. Is this possibly a vm bug or is it more likely a code problem. I am not asking for anyone to solve my code if that is the problem but I have no more ideas about how to find out what the problem is. In case it helps here is the output from java -version
    java version "1.3.1_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
    Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

    case? If so, I suggest that -- if you haven't already
    done so -- that you build a prototype of your project
    consisting only of the socket code that you're having
    problems with. This will obviate the possibility that
    something else in some seemingly unrelated piece of
    code is causing the problem. If you get that to work,
    then add pieces to your prototype until it converges
    with what you have now. That will allow you to
    isolate the piece causing the problem.This is not my first work with sockets in java but I think I may have to do the speration you mention to isolate the problem.
    Secondly, I'm writing this because I have I had a
    similar problem with sockets in C when I was first
    playing with them, and I know that deep down in the
    OS, sockets are sockets, pretty much the same as they
    ever were, and so my advice might carry to JAVA.
    First of all, you need to find out if the connections
    you are creating are blocking or non-blocking,
    including the server socket. If they are blocking,
    which I believe used to be the default, that means
    that your code will stop there and appear to hang
    when what is really happening is that it is just
    waiting for the next piece of data (or next
    connection, for a queue socket). If you've already
    got all that worked out, I recall that C sockets
    would cause an error condition on the port which, if
    not caught and handled, would really gunk things up
    because the port would show up as readable (using the
    tools for handling non-blocking sockets) but there
    would never be any data on it, which originally
    caused my software to hang while trying to read the
    nonexistent data. Go check those things and come
    back.Yes there are blockng calls... s = ss.accept() is a blocking call. Here is the code with more comments as I understand what is happening.
    Socket s = null;
    try{
      // this next line is a blocking call. This thread (only the one) will be waiting until a connection attempt is made
      s = ss.accept();
    }catch(IOException clientConnectError){
      // the accept method may throw an IOException this is
    an error to trap in the client debugging stage and otherwise I don't care so ignore it and jump to the next iteration of the loop.
      continue;
    try{
      // here the whole socket is added to a queue of sockets. 
      rq.addConnection(s);here is my code for the ConnectionQueue of sockets...
    public class ConnectionQueue{
      private LinkedList lElements;
      private boolean bOpen;
      public ConnectionQueue(){
        lElements = new LinkedList();
        bOpen = true;
    /** Adds the socket to the end of the queue.
    @param s The socket to add to queue.
    @exception ConnectionQueueException If this queue has been closed.*/
      public synchronized void addConnection(Socket s)throws ConnectionQueueException{
        if(!bOpen){
          throw new ConnectionQueueException("Request Queue closed.");     
        lElements.addLast(s);
        notify();
    /**Returns the socket at the beginning of the queue.     
    @exception ConnectionQueueException If the queue is closed and empty.*/
      public synchronized final Socket getConnection()throws InterruptedException,ConnectionQueueException{
        if((!bOpen)&&(lElements.size()<=0)){
          throw new ConnectionQueueException("Request Queue Closed");
        while(lElements.size()<=0){
          wait();
          if((!bOpen)&&(lElements.size()<=0)){
            throw new ConnectionQueueException("Request Queue closed.");
        try{
          return (Socket) lElements.removeFirst(); 
        }catch(ClassCastException bad){
          throw new ConnectionQueueException(bad.getMessage());
    /** Closes the queue. A closed ConnnectionQueue will not accept any additional sockets through addConnecion(Socket s). Sockets will still be returned by getConnection() for a closed ConnectionQueue while there are still queued sockets.*/     
      public synchronized void close(){
        bOpen = false;
        notifyAll();
         Well all this code works as it is supposed to. Also the app only dies (and when I mean dies/stops it is dead no more process, no more vm, nothing) when nothing is happening as opposed to if it is really busy in which case it is fine.

  • How can I copy cookies about some web site and paste them into a program's header?

    You may know the programme called Teleport Ultra which allows us to download an entire web site and browse offline. There is a forum I want to download but it doesn't allow to see the pages without logging in. So I want to take the cookies after I log in to site, and put them to the programme. How can I do?
    PS: I have to re-create it like "cookie: name1=value1 name2=value2;" in the program

    *Cookie Exporter: https://addons.mozilla.org/firefox/addon/cookie-exporter/

  • I uninstalled Adobe Air and Adobe Reader and now I cannot reinstall them on the Adobe web site. I go thru the steps on Adobe site and never get a popup to RUN any programs.

    I uninstalled Adobe Air and Adobe Reader and now I cannot reinstall them on the Adobe web site. I go thru the steps on Adobe site and never get a popup to RUN any programs.

    Then there is something seriously wrong with either your
    browser
    Windows
    Internet connection
    I have just downloaded that installer (on Windows 7, using Pale Moon), and the download completed within less than 10 seconds.  And I am some 10,000km away from the Adobe download servers.
    Can you try a different browser?
    Can you download anything to your computer, e.g. from Microsoft?

  • Hello,  Can you please advise me as to the recommended system requirements for Adobe CC for Photoshop, Illustrator, InDesign, and Dreamweaver (all 4 programs). I'm hoping this is summarized somewhere rather than making me look up and compare all four. I'l

    Hello,
    Can you please advise me as to the recommended system requirements for Adobe CC for Photoshop, Illustrator, InDesign, and Dreamweaver (all 4 programs). I'm hoping this is summarized somewhere rather than making me look up and compare all four. I'll be using a windows based PC, and will need a graphics card that can support at least two monitors.

    Hi julir
    check this System requirements | Photoshop
    why photoshop demand?cause photoshop having 3D feature, it mean need high spec,,so if you can run photoshop cc to run ai,indd and dw is posibilty
    regards
    Deto

  • Upon opening LR I receive a "Server Busy" dialoge box: "This action cannot be completed because the other program is busy. Choose 'Switch To' to activate the busy program and correct the problem." I have no other programs open and when I wait a bit it cle

    Upon opening LR I receive a "Server Busy" dialoge box: "This action cannot be completed because the other program is busy. Choose 'Switch To' to activate the busy program and correct the problem." I have no other programs open and when I wait a bit it clears with the 'retry' button. Happened following a recent update. I'd really like this to go away - any ideas?

    For me this happens when I have Zenfolio or Facebook open in Google Chrome, even if Google Chrome is not active.  If you use Chrome, when the error shows up open Chrome and close each one of the tabs and click on the retry in Lightroom.  Also happens if Internet explorer is running with either of these two programs.

  • TS1741 I've downloaded a few apps since I got my ipad 3 two weeks ago...now it just sits on ( waiting ) and wont complete the download. Any ideas? Thanks, Chris

    I've downloaded a few apps since I got my ipad 3 two weeks ago...now it just sits on ( waiting ) and wont complete the download. Any ideas? Thanks, Chris

    Make sure that you do not have a stalled download in iTunes - a song or podcast .... if you have a download in there that did not finish, complete that one first. Only one thing can download at a time on the iPad so that could be what is causing the problem.
    If that doesn't work - sign out of your account, restart the iPad and then sign in again.
    Settings>Store>Apple ID. Tap your ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Go back to Settings>Store>Sign in and then try to update again. Tap one waiting icon only if necessary to start the download stream.
    You can also try deleting the waiting icons - tap and hold down on an icon until it wiggles - the tap the X on the icon to delete it. Then try to download again.
    You can try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your app preferences and device settings again.

  • Making a new tab from link or blank tab it shows my original tab site and i cant do anything with it. how do i fix this!?

    When i add a new tab in all the ways possible it places a new tab but just shows the same site that is on the 1st tab and i cant do anything with it and still says new tab.
    if i wanted to bring a link up in a new tab it does this and if i want a blank tab. i have to open a new window.

    Try the Firefox SafeMode to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    * You can open the Firefox 4.0+ SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    '''''If it is good in the Firefox SafeMode''''', your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes
    ''When you figure out what is causing that, please let us know. It might help other user's who have that problem.''

  • What's the difference between a web site and a web application?

    I'm stumped trying to come up to a difference between a web site and a web application for myself. As I see it, a web site points to a specific page and a web application is more of some sort of 'portal' to content and information.
    But where I'm stuck is that a web application is still viewed through a browser (is it not?) and a web site can still view content dynamically, making the line between web site and application prety gray.
    For instance, does a web site using ASP.NET or AJAX (I assume ASP.NET is AJAX's proprietary sibling, if not, ignore ASP.NET AND concentrate on the AJAX), becomes a web application because it can retrieve data dynamically and asynchronously or would a website
    using PHP and a CMS be more of a web application because it forms the pages on request, based on the request of the client and its content in its databse?
    Or maybe I'm totally wrong here - what differenciates between a web application and a website?
    http://support.peopleperhour.com/entries/68630566--C-mon-lets-Watch-The-Other-Woman-2014-full-movie-online-free
    https://glossicom.zendesk.com/entries/68643806--%D0%BC-v%C9%AA%C9%9Bc-%C3%A4st-Watch-The-Lucy-2014-full-movie-free
    https://cloudhance.zendesk.com/entries/68115098--%D0%BC-v%C9%AA%C9%9Bc-%C3%A4st-Watch-The-Lucy-2014-full-movie-free
    This is totally personal and subjective, but I'd say that a website is defined by its content, while a webapplication is
    defined by its interaction with the user. That is, a website can plausibly consist of a static content repository that's dealt out to all visitors, while a web application depends on interaction and requires programmatic user input and data processing.
    For example, a news site would be a "website", but a spreadsheet or a collaborative calendar would be web "applications". The news site shows essentially the same information to all visitors, while the calendar processes individual data.
    Practically, most websites with quickly changing content will also rely on a sophisticated programmatic (and/or database) backend, but at least in principle they're only defined by their output. The web application on the other hand is essentially a program that
    runs remotely, and it depends fundamentally on a processing and a data storage backend.
    http://support.peopleperhour.com/entries/68125597--%D0%BC-v%C9%AA%C9%9Bc-%C3%A4st-Watch-The-Lucy-2014-full-movie-free
    https://cloudhance.zendesk.com/entries/67541393--Watch-The-Godzilla-2014-free-Online-Full-Movie-HD-Quality
    http://support.peopleperhour.com/entries/68168787--Watch-The-Godzilla-2014-free-Online-Full-Movie-HD-Quality
    https://glossicom.zendesk.com/entries/68161538--Watch-The-Godzilla-2014-free-Online-Full-Movie-HD-Quality
    There is no real "difference". Web site is a more anachronistic term that exists from the early days of
    the internet where the notion of a dynamic application that can respond to user input was much more limited and much less common. Commercial websites started out largely as interactive brochures (with the notable exception of hotel/airline reservation sites).
    Over time their functionality (and the supporting technologies) became more and more responsive and the line between an application that you install on your computer and one that exists in the cloud became more and more blurred.
    If you're just looking to express yourself clearly when speaking about what you're building, I would continue to describe something that is an interactive brochure or business card as a "web site" and something that actually *does something that feels
    more like an application as a web app.
    The most basic distinction would be if a website has a supporting database that stores user data and modifies what the user sees based on some user specified criteria, then it's probably an app of some sort (although I would be reluctant to describe Amazon.com
    as a web app, even though it has a lot of very user-specific functionality). If, on the other hand, it is mostly static .html files that link to one another, I would call that a web site.
    Most often, these days, a web app will have a large portion of its functionality written in something that runs on the client (doing much of the processing in either javascript or actionscript, depending on how its implemented) and reaches back through some
    http process to the server for supporting data. The user doesn't move from page to page as much and experiences whatever they're going to experience on a single "page" that creates the app experience for them.

    ...can i make as many iweb websites as i want? ...and as many blogs as i want? ...i have never made one before....
    ....although, i do have my own small business and i do have a website that i paid a guy to make and also host....(which is a waste of $$$$ in my opinion as i think i can do a better job making one myself through iweb) ....
    ...anyways, i know it is splitting hairs but what exactly is the diff b/w a blog and a website ....i am under the impression that a blog is just a personal newsletter sort of thing,...?

  • JCo server programming, properties and connection settings

    Greetings, SAP professionals.
    The reason I come to this forum is that I'm hoping to gain some insights into the use of the SAP Java Connector (JCo). I am a developer who was tasked with making a new component for a systems integration application. As is typical of integration software, our app can link together various different systems using a variety of protocols, as well as providing the means to apply business logic on messages passed from one location to another. We already have a connector acting as an SAP client which was implemented using JCo. Now, we were asked to develop a new component: a server capable of accepting RFCs from a remote SAP system acting as client. The server is to be created using the JCo classes, so basically an extension of JCo.Server, with some logic for creating function templates from configuration files.
    However, while I'm understanding the structure of the Java API, it's not entirely clear to me just what the classes do. I've found the JavaDoc for JCo to be mostly descriptive of the interface of classes and methods, but not really explaining what these achieve, or how. So I'm hoping to be set straight, as I fear I'm kind of misunderstanding the functionality of JCo... Being mainly an integrations developer, I unfortunately often have to settle for gaining a superficial knowledge of a variety of systems to quickly interface with them, so I don't have any prior knowledge of SAP but still need to be able to implement something with JCo without too much delay.
    The most important question I have is this: when a JCO.Server implementation is started, does it act as a fully standalone component capable of receiving calls, or does it merely act as a sort of listener for some main SAP system? I'm not talking about a reliability on the two .dll files (or .so for Linux) that are required for the use of JCo, I just wish to know if the JCo package is entirely self-sufficient for server functionality or if it is intended to be linked to some SAP system.
    A second problem I have is that the parameters passed to various constructors aren't clear to me... I'm not familiar with SAP terminology, nor have I worked with any client apps that make use of an SAP system.
    The meaning of client strings, gwhost, gwservice, ashost, system IDs and program IDs mostly elude me, especially when it comes to knowing what client parameters must match what server parameters.
    In order to familiarize myself with the classes, I've tried playing around with them a bit trying to create a small test app that first starts a JCO.Server instance, then tries to make a remote function call to it with a JCO.Client (within the same class, for simplicity and debugging purposes). I was wondering if this actually makes sense... Would a JCo client be capable of connecting to a JCo server, all running purely in Java, or is that nonsense?
    To eliminate some common troubleshooting options, I'll quicly describe the steps I've taken:
    Both librfc32.dll and sapjcorfc.dll were placed in the Windows system32 folder. Maybe only librfd32 needs to be placed there, but I copied both anyway to make sure.
    The directory containing the jar file and both dll files is included in my environment path variable.
    I've added a line to the C:\Windows\system32\drivers\etc\services file as follows:
    sapgw00          3300/tcp                           #SAP System Gateway Port
    I've opened port 3300 in my Windows firewall. In fact, I also tested with the firewall completely turned off.
    However, I do not manage to get my test class to work. I've tried ports 3300, 3200 and 3600. I've tried various permutations of the client and server properties. I've tried removing the line from the services file, which would prompt the client to state upon connecting that the service "sapgw00" is unknown. When I add it back in, the error changes to "partner not reached", so it is definitely picking something up.
    The server itself starts just fine, but connecting through a client doesn't work. My class source code is posted below. Maybe what I'm trying to do doesn't make any sense, but at the moment it's my best guess.
    I realize this is a pretty long post and the class, while not exactly big, also implies a bit of reading of its own. But if anyone could give me any answers that are new to me, I'd be hugely grateful. Right now I'm kind of stuck, and just setting up the service and letting our customer test on it is a somewhat slow approach that can't match developing and testing on one and the same host.
    Preliminary thanks to everyone who took the effort to read this.
    //Start of code
    import java.util.Properties;
    import com.sap.mw.jco.IFunctionTemplate;
    import com.sap.mw.jco.IMetaData;
    import com.sap.mw.jco.IRepository;
    import com.sap.mw.jco.JCO;
    public class Test {
         public static void main(String[] args) {
              Test test = new Test();
              ServerThread serverThread = test.new ServerThread();
              serverThread.start();
              while(!serverThread.isReady) {
                   try {
                        Thread.sleep(5000);
                   } catch(final InterruptedException i) {
                        System.out.println("Rudely awakened");
              try {
    //               JCO.Function func = getSampleFunction(test, "STAY");
    //               serverThread.server.handleRequest(func);
    //               System.out.println(func.getExportParameterList().toXML());
    //               func = getSampleFunction(test, "STOP");
    //               serverThread.server.handleRequest(func);
    //               System.out.println(func.getExportParameterList().toXML());
                   final Properties clientProps = getClientProps();
                   JCO.Client client = JCO.createClient(clientProps);
                   client.connect();
                   IRepository rep = JCO.createRepository("1", client);
                   IFunctionTemplate templ = rep.getFunctionTemplate("TEST_FUNC");
                   JCO.Function function = templ.getFunction();
                   function.getImportParameterList().setValue("STAY", "FIELD1");
                   client.execute(function);
                   JCO.Function function2 = templ.getFunction();
                   function2.getImportParameterList().setValue("STOP", "FIELD1");
                   client.execute(function2);
              } catch(final Exception e) {
                   e.printStackTrace(System.out);
                   serverThread.requestStop();
                   while(serverThread.isAlive) {
                        try {
                             Thread.sleep(5000);
                        } catch(final InterruptedException i) {
                             System.out.println("Rudely awakened");
              } finally {
         private static Properties getClientProps() {
              final Properties props = new Properties();
              props.setProperty("jco.client.client", "100");
              props.setProperty("jco.client.user", "");
              props.setProperty("jco.client.passwd", "");
              props.setProperty("jco.client.lang", "");
              props.setProperty("jco.client.sysnr", "00");
              props.setProperty("jco.client.ashost", "/H/localhost/S/sapgw00");
              props.setProperty("jco.client.gwhost", "localhost");
              props.setProperty("jco.client.gwserv", "sapgw00");
              return props;
         public class ServerThread extends Thread {
              public void run() {
                   isAlive = true;
                   IRepository repos = new TestRepository("testrep");
                   repos.addFunctionInterfaceToCache(getFunctionInterface());
                   server = new TestServer(repos);
                   server.start();
                   System.out.println("Server successfully started");
                   isReady = true;
                   while(!stop) {
                        try {
                             Thread.sleep(1000);
                        } catch(final InterruptedException i) {
                             System.out.println("Wouldn't let me sleep...");
                        stop = server.stopRequested;
                   server.stop();
                   isAlive = false;
                   System.out.println("Server successfully stopped");
              public void requestStop() {
                   server.requestStop();
              public TestServer server;
              public boolean isReady = false;
              public boolean isAlive = false;
         public class TestServer extends JCO.Server {
              public TestServer(IRepository rep) {
                   super("localhost", "sapgw00", "PROGID", rep);
              public void handleRequest(JCO.Function fct) {
                   try {
                        JCO.ParameterList importParams = fct.getImportParameterList();
                        final String importXML = importParams.toXML();
                        System.out.println("XML representation of import parameters: ");
                        System.out.println(importXML);
                        final String input = importParams.getString("FIELD1");
                        System.out.println("FIELD1 value: " + input);
                        JCO.ParameterList exportParams = fct.getExportParameterList();
                        if(input.equals("STOP")) {
                             exportParams.getField("FIELD2").setValue("OK");
                             stopRequested = true;
                   catch(JCO.AbapException ex) {
                        throw ex;
                   catch(Throwable t) {
                        throw new JCO.AbapException("SYSTEM_FAILURE", t.getMessage());
              public boolean checkAuthorization(String functionName, int authorMode, String partner, byte[] key) {
                   System.out.println(functionName + " " + partner);
                   return true;
              public void requestStop() {
                   stopRequested = true;
              public boolean stopRequested = false;
         public class TestRepository extends JCO.BasicRepository implements IRepository {
              public TestRepository(String name) {
                   super(name);
         public static IMetaData getFunctionInterface() {
              JCO.MetaData metaData = new JCO.MetaData("TEST_FUNC");
              metaData.addInfo("FIELD1", IMetaData.TYPE_STRING, 4);
              metaData.setFlags(0, IMetaData.IMPORT_PARAMETER);
              metaData.addInfo("FIELDX", IMetaData.TYPE_STRING, 8);
              metaData.setFlags(1, IMetaData.IMPORT_PARAMETER & IMetaData.OPTIONAL_PARAMETER);
              metaData.addInfo("FIELD2", IMetaData.TYPE_STRING, 2);
              metaData.setFlags(2, IMetaData.EXPORT_PARAMETER);
              return metaData;
         public static JCO.Function getSampleFunction(Test test, String s) {
              TestRepository testRep = test.new TestRepository("testrepository");
              testRep.addFunctionInterfaceToCache(getFunctionInterface());
              JCO.Function func = testRep.getFunctionTemplate("TEST_FUNC").getFunction();
              func.getImportParameterList().setValue(s, "FIELD1");
              return func;
         private static boolean stop = false;

    If I understood you correctly, you want to provide a "service" that can be called from SAP. To provide this service you've chosen to implement an (external) RFC server program via JCo. One common method for RFC server programs is to register in SAP on the gateway - you do this by supplying the three parameters
    <ol>
    <li><b>jco.server.gwhost</b> -  SAP gateway host on which the server should be registered (so this would be the server name or IP address of the SAP gateway; localhost is only correct, if your RFC server program runs on the same server as the SAP gateway)</li>
    <li><b>jco.server.gwserv</b>  - Gateway service, i.e. the port on which a registration can be done</li>
    <li><b>jco.server.progid</b> - Program ID under which your RFC server program can be reached (free, made-up case sensitive name, that should represent the service your RFC server is providing)</li>
    </ol>
    So essentially you're creating a listener, that is registered in SAP and waits for any invocations. Within SAP they will define a <i>RFC destination</i>, which basically represents a TCP/IP connection pointing to the SAP gateway where you registered with the given program ID. If you want more details, check the SAP help pages for <a target="_blank" href="http://help.sap.com/saphelp_nw04/helpdata/en/22/04262b488911d189490000e829fbbd/content.htm">RFC destinations</a> (you're looking for destination type <b>T</b>, see explanations <a target="_blank" href="http://help.sap.com/saphelp_nw04/helpdata/en/22/042652488911d189490000e829fbbd/content.htm">here</a>).
    Usually gateway host and service (port) are given to you by the SAP basis folks and you tell them which program ID you're using. They will then enter those parameters in an RFC destination of type <b>T</b> in SAP. So no need for any of the client parameters you've mentioned. Although, I'd like to repeat, it's usually handy to also have SAP logon parameters maintained on your RFC server program, so that you can utilize the repository data from SAP (might be irrelevant in your case).
    Hope this clarifies it a bit...

Maybe you are looking for

  • PS (plan vs actual costs) Report

    Hi, I have to generate the above report. How can I diffrentiate between Plan cost and actual cost. Is there any business contect report for this ? can anybody throw light on this. Regards, Bill

  • Error on sender CC file adapter FTP

    Hi i have the scenario FILE-WS-FILE (synchronous) where im having problems in my sender CC, at the channel monitor servlet is showing the next errors while trying to get the message on the XML file. MP: unexpected exception caught com.sap.aii.af.serv

  • Edit Extended Characters

    Run'n HS5.0 n'wood lke to edt my extended characters. I use alot that are not on the list, and a lot that are on the list, I don't use. Can I edit this list and put in the ones that I use? thank you JWC

  • How to get notified when new comment  is left on blog?

    I'd like to be notified (preferrably by e-mail) when a new comment is left on my blog. Is that possible in iWeb '09?

  • Restoring archived data from the blackberry protect site

    Hi, I just switched devices I use to use a 8520 curve now I'm using a 9380, so I want to know do I restore my archived back up cause my previous device doesn't appear on the blackberry protect site but my archived data seem to be there ? Thanks in ad