Signals in Java

I am running a Java program in Windows NT. I want to do a clean shutdown whenever a signal is received.
I have registered the following Signals in the Signal Handler INT,TERM,ABRT. It works well for Cntrl-C, Window Close.
When i go to the Task Manager and Kill the Java Process itself nothing happens. How do i trap that.
Please let me knw ASAP.

How can you trap, when somebody blows up the comp?

Similar Messages

  • SOLARIS SIGNALS in JAVA

    Hi,
    I am writing a java program which will be triggered by a shell script on solaris machine. how can i handle signals SIGUSR, SIGUSR2 etc... in the java program?
    Thanks in advance
    Regards
    Hunger

    Hi,
    the following trick might only work with some versions of Sun JDKs and is not recommended, however:
    There is a class called sun.misc.Signal and an interface sun.misc.SignalHandler which does, what you need. But use it with care! The VM uses its own signal handlers and might interfere with yours. There is an option to the VM "-Xrs" which influences how the VM handles signals and which signals it handles by itself.

  • Send signal from java program to Excel document

    Hi
    I have a Java-program that once a day brings information from a website on the internet. When this has been done, I want to send a signal to an Excel document to run a vba-macro. The "signal" can e.g. be to put a value in a certain cell in the Excel document.
    Any ideas on how to do this?

    Thanks gtRpr I didnt actually know what webservices are so I looked them up, below is one of definintions i got, and this is not what I want. The class that i write will be only used by me and only to extract data from one website.
    >
    Web services allow organizations to communicate data without intimate knowledge of each other's IT systems behind the firewall.
    secruity is not a problem, so there should be no need to encypt. Here is the kind of steps that I have put together so far, please could you comment on them...
    1. find out what the textfields are called on the website that need //do this by hand once
    2. parse the website username and password
    3. traverse to correct web page
    4. return page info in xml format //sorry im new to this side of programming, is it easy to convert html - xml
    5. need to strip out all unessary xml comments to reveal me with my specific data
    Thanks
    Edited by: calypso on Aug 8, 2008 2:15 AM

  • Signal strength java WIFI app

    hi
    im making a application that searches for all packets retrieved on a network and where
    they are comming from using jpcap.
    my question is, and i have been searching on google and cannot find much on. is that
    how would you get the signal strength of a wireless ap
    im guessing that you would just ping it.
    e.g.
    send a packet at it and determine how long it took to get back to you
    the ferther away the longer time :)
    anyideas
    there's probly a easy tool in java that you can use that i have stupidly missed out on

    morgalr wrote:
    jwenting wrote:
    morgalr wrote:
    Um, NO. Radio Waves travel at 300,000,000 meters per second, approximately the speed of light, Actually they travel AT the speed of light, which is approximately 300E6 meters per second in vacuum.
    Of course the speed of light is itself affected by the medium through which the radiation is travelling, usually meaning that the actual speed will be slightly lower than the speed in vacuum (though I think I read somewhere of an experiment leading in at least one case to a speed faster than that in vacuum, don't know whether that was ever reliably replicated).It seems to me that that is approximately the speed of light--300E6==300,000,000--unless you want to put qualifiers onto it--like STP or in a a vacuum.your post could have been interpreted as stating that radio waves travel at approximately the speed of light and that they travel at 300 million meters per second ;)

  • Java Signals

    I'm posting this here because I do not know of a better way to address the Java development team directly.
    Requests for a signal handling facility have been made since the earliest releases of Java. The response from the Java development team seems to be that signals are platform dependent and therefore does not meet the demands of WORA. However, what about adding Java's own signal handling facility instead of trying to interface with the platform's?
    I was recently working on a project where I needed two threads to be able to notify each. Instead of using signals, I had them routinely stop and check some shared variable. However, that is more expensive than necessary and it would have been preferred if thread 1 could have thrown a singal to thread 2.
    Note that what I needed was not a way for the operating system to signal Java, but instead a way for Java to signal Java.
    I would propose some Signal object, much like the Exception object. Signals in Java would, of course, be implemented as objects and be capable of carrying more information than their C-like counterparts. It would also be subclassable so that even more information could potentially be passed between threads. A thread would then register some method as signal handler for a particular kind of Signal object (similar to the way that current Java code catches different kinds of Exception objects). If the signal is thrown, execution of the catching thread halts, jumps to the signal handler method, clears the handler registration, and returns to the point of discontinuation. This can be done without need for implementing platform-specific signal handling.
    Even though the above description does not include platform specific signals. It would also be possible to subclass Signal and create a generic SystemSignal object. This SystemSignal object would incur the signal handler for any thread that is listening for a SystemSignal object. The object would contain some getName() method to fetch the platform name of the object (i.e. SIGTERM). If a SystemSignal handler had been registered, the JVM would construct a SystemSignal object and set the name. It would then invoke the signal handler and it would be up to the handler to analyze the signal with getName() and determine if it wants to perform an action for this signal. This would encourage more developers to use platform specific signals in their Java code. However, those developers that needs this functionality are not working around it in Java, they are instead turning to C or C++ for the functionality they require for the entire project or for JNI calls. I don't believe it would be in the best interest of the language to try to discourage the practice of using platform specific signals.
    Thanks,
    Jonathan A. Kennedy
    Programmer/Analyst

    Seems to me there are plenty of ways in Java to handle this issue without trying to get the language changed. Here's a simple one to get you started; I don't know if this is exactly what you meant but it sounds like it.
    You need a way for a Thread to be "notified" of some event by another thread. So, write a subclass of Thread (call it NotifiableThread) that has a notify() method. Then NotifiableThread A, or any code for that matter, can call NotifiableThread B's notify() method at any time. NotifiableThread B's notify() method would be coded to do whatever is supposed to happen when the event is signalled. This is just a rough outline, you would have to deal with synchronization issues and so on.
    Another common Java design pattern you could use is the Listener pattern, where one object registers itself as a Listener with another object that is generating events.

  • RFID in JAVA

    Anyone know how to get information on reading RFID signals into JAVA? What classes or wrapper classes does one need?
    email me at [email protected]
    Thanks!

    A Google search
    http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Java+RFID
    turned up this:
    http://java.ittoolbox.com/news/dispnews.asp?i=109973&t=99
    Google is always your friend. - MOD

  • Concurrency with locks and wait/signal. Is it ok?

    Hello,
    I'm relatively new in concurrency. I've write this code that seems to work, but I'm not sure if there is any error (the concurrency concepts are not still clear for me).
    In the following class "diskFile", I'll start 10 threads executing the class "diskCacheDataOneCall". The question is that the "populateCacheFromDisk" method should wait until 10 threads are finished and, if any thread produces an error, interrupt all threads and finish.
    The code seems to work, but I have some questions like if I should synchronize the static variables Lock and Condition before using them.
    Anyway, I'd like that an "expert" on concurrency tells me if this code is acceptable, or what kind of improvements can do (or, if there is some mistake, how to correct it).
    I've spent many time reading tutorials about concurrency, and this is the result. Really, I'm not sure if I'm doing the things well, that's why I need the opinion of an expert in order to get better on concurrency.
    Thanks in advance.
    public class diskFile
    // Static variables for threading.
    public static Lock lock = null;
    public static Condition cdFinished = null;
    public static int numActiveThreads = 0;
    public static Exception loadException = null;
    // Main function
    public static void populateCacheFromDisk() throws cacheServletException
    ArrayList<Thread> arrThread = new ArrayList<Thread>();
    // Init static variables.
    lock      = new ReentrantLock();
    cdFinished      = lock.newCondition();     
    numActiveThreads = 0;
    loadException = null;
    try
    // Iterate 10 times (for simplicity) ...
    for (int i = 0; i < 10; i++)
    // Create THREAD and store its reference
    Thread thr = new Thread(new diskCacheDataOneCall());
    thr.start();
    arrThread.add(thr);
    // Increment "numActiveThreads"
    lock.lock();
    numActiveThreads++;
    lock.unlock();
    // Her we wait while no error happens and still active threads
    lock.lock();
    while ( (loadException == null) && (numActiveThreads > 0) )
    cdFinished.await();
    // If an error happens in any thread, then interrupt every active thread.
    if (loadException != null)
    for (int i = 0; i < arrThread.size(); i++)
    Thread thr = arrThread.get(i);
    if (thr.isAlive()) thr.interrupt();
    throw loadException;
    catch (Exception e) { throw new cacheServletException(); }
    finally { lock.unlock(); }
    public class diskCacheDataOneCall implements Runnable
    public diskCacheDataOneCall() {}     
    public void run()
    try
         diskFile.getCacheDataFromDiskOneCall(); // Load data from disk.
    // Decrement "numActiveThreads"
         diskFile.lock.lock();
         diskFile.numActiveThreads--;
    catch (Exception e)
    diskFile.lock.lock();
    diskFile.loadException = e;
    finally
    // Always signal and unlock.
    diskFile.cdFinished.signal();
    diskFile.lock.unlock();
    }

    Hello David,
    Sorry but the code does not work. An IllegalMonitorStateException is throwed. Here I show you a simplified version (now with ThreadPoolExecutor):
       // Main class (it triggers "maxActive" threads)
       Lock lock  = new ReentrantLock();
       Condition cdFinished = lock.newCondition();       
       numActiveThreads = 0;
       loadException = null;
       try
        ExecutorService ex = Executors.newFixedThreadPool(numActiveThreads);
        for (int i = 0; i < numActiveThreads; i++) ex.execute(arrTasks.get(i));
        lock.lock();
        while ( (loadException == null) && (numActiveThreads > 0) )
                   cdFinished.await();
        ex.shutdown();
       catch (Exception e) { throw e; }
       finally { lock.unlock(); }
      // Every thread.
      public void run()
       try
        doSomething();
        diskFile.lock.lock();
        diskFile.numActiveThreads--;
       catch (Exception e)
        diskFile.lock.lock();
        diskFile.loadException = cse;
       finally
        diskFile.cdFinished.signal();
        diskFile.lock.unlock();
      }The exception is:
    // Fail in the "signal" (finally section)
    Exception in thread "pool-1-thread-1" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.signal(AbstractQueuedSynchronizer.java:1666)
    at com.vcfw.cache.cache.disk.diskCacheDataOneCall.run(diskCacheDataOneCall.java:44)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    // Fail in the "unlock" (finally section)
    Exception in thread "pool-1-thread-2" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:125)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1102)
    at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
    at com.vcfw.cache.cache.disk.diskCacheDataOneCall.run(diskCacheDataOneCall.java:43)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    Some threads fail executing the signal, and some threads fail executing ythe unlock. An IllegalMonitorStateException seems to mean that the lock was not acquired by the thread, but I'm not able to see the mistake.
    Can you help me?
    Thanks.

  • Memory handling in java

    how to increase size of java program......can it be possible.......
    i faced this question in the interview......
    waiting for your answer....

    Type java -X on command line. You should get this.
        -Xmixed           mixed mode execution (default)
        -Xint             interpreted mode execution only
        -Xbootclasspath:<directories and zip/jar files separated by ;>
                          set search path for bootstrap classes and resources
        -Xbootclasspath/a:<directories and zip/jar files separated by ;>
                          append to end of bootstrap class path
        -Xbootclasspath/p:<directories and zip/jar files separated by ;>
                          prepend in front of bootstrap class path
        -Xnoclassgc       disable class garbage collection
        -Xincgc           enable incremental garbage collection
        -Xloggc:<file>    log GC status to a file with time stamps
        -Xbatch           disable background compilation
        -Xms<size>        set initial Java heap size
        -Xmx<size>        set maximum Java heap size
        -Xss<size>        set java thread stack size
        -Xprof            output cpu profiling data
        -Xrunhprof[:help]|[:<option>=<value>, ...]
                          perform JVMPI heap, cpu, or monitor profiling
        -Xdebug           enable remote debugging
        -Xfuture          enable strictest checks, anticipating future default
        -Xrs              reduce use of OS signals by Java/VM (see documentation)
        -Xcheck:jni       perform additional checks for JNI functions
    The -X options are non-standard and subject to change without notice.

  • System.loadLibrary("signal") in windows

    getting error:
    no signal in java.library.path.
    Can someone please help.
    Adam.

    It is looking for a file called signal.dll in the OS path specified by the property "java.library.path".
    And it doesn't find it.
    You can print the path that it is looking on with the following
    System.out.println("java.library.path = " + System.getProperty("java.library.path"));

  • How to set the heap size of JVM

    please let me know that how to set the heap size of JVM

    C:\>java -X
        -Xmixed           mixed mode execution (default)
        -Xint             interpreted mode execution only
        -Xbootclasspath:<directories and zip/jar files separated by ;>
                          set search path for bootstrap classes and resources
        -Xbootclasspath/a:<directories and zip/jar files separated by ;>
                          append to end of bootstrap class path
        -Xbootclasspath/p:<directories and zip/jar files separated by ;>
                          prepend in front of bootstrap class path
        -Xnoclassgc       disable class garbage collection
        -Xincgc           enable incremental garbage collection
        -Xbatch           disable background compilation
        -Xms<size>        set initial Java heap size
        -Xmx<size>        set maximum Java heap size
        -Xss<size>        set java thread stack size
        -Xprof            output cpu profiling data
        -Xrunhprof[:help]|[:<option>=<value>, ...]
                          perform JVMPI heap, cpu, or monitor profiling
        -Xdebug           enable remote debugging
        -Xfuture          enable strictest checks, anticipating future default
        -Xrs              reduce use of OS signals by Java/VM (see documentation)look at the -Xm? lines
        -Xms<size>        set initial Java heap size
        -Xmx<size>        set maximum Java heap sizeThis can be used e.g. like this:java -Xms8M -Xmx32M MyProgwhich runs MyProg in a java VM with the initial heap size of 8 MB and a maximum heap size of 32 MB.
    - Marcus

  • How to read long line from text file

    Hi,
    I just faced problem when reading a big text file.
    BufferedReader br = new BufferedReader(new FileReader("D:\\afile.txt"));
    String str;
    int i;
    while ((str = br.readLine())!=null)
    i++;
    //do some work here...
    ...This code throws exception:
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap spaceSo I thought file line is very long. When I opened it in FAR it only displays no more than 4096 characters as a line.
    Help me to read a text file that's line is very long?

    try,
    $ java -X
    -Xmixed mixed mode execution (default)
    -Xint interpreted mode execution only
    -Xbootclasspath:<directories and zip/jar files separated by ;>
    set search path for bootstrap classes and resources
    -Xbootclasspath/a:<directories and zip/jar files separated by ;>
    append to end of bootstrap class path
    -Xbootclasspath/p:<directories and zip/jar files separated by ;>
    prepend in front of bootstrap class path
    -Xnoclassgc disable class garbage collection
    -Xincgc enable incremental garbage collection
    -Xloggc:<file> log GC status to a file with time stamps
    -Xbatch disable background compilation
    -Xms<size> set initial Java heap size
    -Xmx<size> set maximum Java heap size
    -Xss<size> set java thread stack size
    -Xprof output cpu profiling data
    -Xrunhprof[:help]|[:<option>=<value>, ...]
    perform JVMPI heap, cpu, or monitor profiling
    -Xdebug enable remote debugging
    -Xfuture enable strictest checks, anticipating future default
    -Xrs reduce use of OS signals by Java/VM (see documentation)
    -Xcheck:jni perform additional checks for JNI functions
    The -X options are non-standard and subject to change without notice.

  • Out of memory errors w/ MappedByteBuffers

    Hello,
    I'm having problems using a MappedByteBuffer on a file that is just over 1 gig. I see this error:
    file size: 1104924640
    java.io.IOException: Map failed
            at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:761)
            at com.ibm.esupport.Test.main(Test.java:32)
    Caused by: java.lang.OutOfMemoryError: Map failed
            at sun.nio.ch.FileChannelImpl.map0(Native Method)
            at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:758)
            ... 1 moreHowever, if I use the same code on a file of only 600 mb, it runs just fine. I also notice if I set incremental garbage collection on run (-Xincgc), it'll work on the 1 gig file but perf seems slower (to me). Here is my code:
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    public class Test {
        public static void main(String[] args) {
            String filename = "c:/tmp/my_large_file";
            // open file
            File f = new File(filename);
            FileInputStream in = null;
            try {
                in = new FileInputStream(f);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.exit(0);
            FileChannel fc = in.getChannel();
            MappedByteBuffer bb = null;
            try {       
                // Get the file's size and then map it into memory
                long sz = fc.size();
                //DEBUGGING
                System.out.println("file size: " + sz);
                bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(0);
            // close flie
            try {
                bb.clear();
                bb = null;
                fc.close();
                fc = null;
                in.close();
                in = null;
            } catch (IOException e) {
                e.printStackTrace();
    }I'm running this on Windows XP Professional with 2 gig of RAM. Any help or direction anyone could give I'd appreciate it. I'd rather not run with incremental garbage collection. Shouldn't this work?
    -jeff

    give the jvm more memory
    with -Xms
    -Xmx
    java -X
    -Xmixed mixed mode execution (default)
    -Xint interpreted mode execution only
    -Xbootclasspath:<directories and zip/jar files separated by ;>
    set search path for bootstrap classes and resources
    -Xbootclasspath/a:<directories and zip/jar files separated by ;>
    append to end of bootstrap class path
    -Xbootclasspath/p:<directories and zip/jar files separated by ;>
    prepend in front of bootstrap class path
    -Xnoclassgc disable class garbage collection
    -Xincgc enable incremental garbage collection
    -Xloggc:<file> log GC status to a file with time stamps
    -Xbatch disable background compilation
    -Xms<size> set initial Java heap size
    -Xmx<size> set maximum Java heap size
    -Xss<size> set java thread stack size
    -Xprof output cpu profiling data
    -Xfuture enable strictest checks, anticipating future default
    -Xrs reduce use of OS signals by Java/VM (see documentation)
    -Xcheck:jni perform additional checks for JNI functions
    -Xshare:off do not attempt to use shared class data
    -Xshare:auto use shared class data if possible (default)
    -Xshare:on require using shared class data, otherwise fail.
    The -X options are non-standard and subject to change without notice.}

  • Coherence averaging without while loop

    Hi all,
    I attached a VI (Coherence.vi using LabVIEW 2011) that calculates and plots the coherence for two simulated signals. It works fine but I want to make a change that I don't know how to manage.
    I want to elimnate the while loop (as I am planning to convert this VI into dll and use it in JAVA appilcation) and do the averaging in an alternative way without using while or for loop.
    The problem with the while/for loop is that the dll doesn't give any output except if the while/for loop is stopped.
    Is there any ideas?
    Attachments:
    Coherence.vi ‏24 KB

    Hi Cowboy12,
    From what I understand, it looks like the averaging VI in your code uses uninitialized shift registers to store previous data, similar to functional global variables.  It seems that each time you are calling this VI from java the result exits out of LabVIEW memory after executing.  This means that each time you call the VI from java you are getting a new instance of it with no memory of the previously averaged signal.
    I think your best bet is to keep the while loop in LabVIEW, so that the current averaging VI works appropriately.  If you really must remove the while loop, then you could write your own version of the averaging VI that takes in the last averaged signal and feeds it into the currently uninitialized shift register.  You would then also need some way of storing this averaged signal in Java and then sending it back into LabVIEW the next time you call the VI.  However, this seems like a very complicated way to obtain the result you want.
    Hope this helps!
    Lindsey W. | Applications Engineer | National Instruments

  • Serial Port Progamming?

    My robotics club us attempting to send out signals from the Serial Port that would be recieved by a chip and interpret it to do other functions. We can recieve Serial Signals with the chip, but we don't know how to send out Serial signals using Java. An example of the type of signal we would like to send would be just sending out a byte of information (say the number 1 or something). Anyways. anyone's help would be MUCH (so much) appreciated! Thanks!
    Always, Jeff

    I need some basics. like isn't there a dll. fromcomm
    api? where do I put the dll?
    Is there some sample code for a program that just
    sends data?
    thnxsRead the link dude. It's not that hard. It's all
    spelled out.Do you get off on being an amazing A-hole? seriously. Do you remember learning programming for the first time? Sometimes you just got STUCK. Sometimes things were hard. Topics that might seem easy or trivial to you right now, might at one time have been difficult for you.
    Don't act like you were born knowing all of this stuff. Sure all of the information has been posted here, but I'm guessing since he's new to this that maybe he doesn't know what to do with all of the information. That is part of learning how to be a programmer and that's the part he's learning right now, so how about you back off and stop being such a ***** to everyone in here that doesn't immediate get something.

  • Help need with CMR

    I am getting the following error when attempting to use CMR. From what I have read so far I thought I only had to provide an abstract get/set method in the entitybean class?
    C:\Sun\NetBeans3.6\SunAppServer8\domains\domain1\generated\ejb\j2ee-apps\ImportData\acre\entitybeans\signals\SignalsBean497127157_ConcreteImpl.java:10: acre.entitybeans.signals.SignalsBean497127157_ConcreteImpl is not abstract and does not override abstract method setSignalEvents(java.util.Collection) in acre.entitybeans.signals.SignalsBean
    public class SignalsBean497127157_ConcreteImplI have two enity beans: SignalsBean and SignalEventsBean (1:M, so each SignalsBean Can reference Many SignalEventsBeans) The relationship is defined in the deploy tool but this does not make a difference.
    Now I also have a field signalEvents available as a persistent field, but If i make this a persistent field it is left unmapped when creating the database mappings and generates an error.
    sun-cmp-mappings.xml exists but has invalid contents: sizeColumnName() == 0 Which makes sense really!
    If I specify a secondary table using advance settings and then map Signals.Signal_ID to Signal_Events.Signal_ID I get this error:
    JDO72316: The field signalEvents must be a relationship.
    Change the field's type to be a collection or other CMP bean.Please help, been stuck reagrding this all day

    I eventually found it was due to the relationships I had set up with the deploy tool for the JAR. I was setting the field to the primary key field of Entity Bean A which is the FK of Entity Bean B. I should have set it to the realtionship field created because of the abstract CMR get/set methods

Maybe you are looking for