Thread.stop() -- Why is it deprecated ? - What alternatives ?

Hi,
I'm creating an XMPP server in Java and I have a problem. I have a thread that run the SAX parser and is constantly blocking to recive data from my socket. Now the problem is that at some point (after the authentication) I need to stop the XML parsing.
The only way I can do this, I think, is by using the Thread.stop() method, but it is deprecated :(
I read the FAQ about this deprecation but the alternatives given can't work for me:
- I can't close the eocket because I need to read another XML document right after on the socket
- I can't call Thread.interrupt() because the thread is blocking on an IO
- I can't use a shared variable because the thread is blocked inside the SAX parser that call from time to time a callback. I can't modify the SAX code :(
Does anyone have an idea how to make my thread stop the parsing ?
Thanks
Mildred

If you've read the "FAQ" on deprecation of stop etc then you already know why stop() is deprecated - it is inherently unsafe as you can't know for sure what your thread was doing when you tried to stop it. Further, what those documents don't tell you is that Thread.stop doesn't break you out of most blocking situations any way - so it wouldn't necessarily help even if it weren't deprecated.
I don't know the I/O or threading architecture of what you are working with so the following may not be applicable, but hopefully something will help:
One of the alternatives you didn't mention is setting the SO_TIMEOUT option on the socket so that your thread can periodically check if its actually been cancelled. I don't know if that is possible in this case it depends on how the use of sockets gets exposed by the library.
Other possibilities for unblocking a thread are to give the thread what it is waiting for - some data on the socket in this case. If you can send something that can be interpreted as "stop looking for more data", or if you check for cancellation before trying to interpret the data at all, then you can unblock the thread by writing to the socket. Whether this is feasible depends on how the real data is written to the socket.
Final possibility is to create a new thread to do the socket reading. Your parser thread can then read from a BlockingQueue, for example, that is populated with data from the socket thread. You can use interrupt() to cancel the parser thread and just ignore the socket thread - which presumably will unblock when the next real data arrives.

Similar Messages

  • How to stop a thread without the deprecated Thread.stop() method?

    Hi,
    I am writting a server application that launches threads, but the run() implementation of these threads are not written by me (i.e. i have no control over them): they are third-party programs. That's why i could not use the well known Java tutorial way to stop a thread (i.e. with a global variable that indicates the thread state).
    I would like my server to be able to stop these threads at any time, but without using the deprecated Thread.stop() method.
    Any ideas ?
    Thanks in advance,
    Fabien

    Thanks Pandava!
    I was arrived at the same conclusion... As to me, it is a very bad issue, because it means for example that a servlet server can not stop any servlet it launches (especially for preventing infinite loops).
    If i want to be strictly JDK 1.4 compliant, i should not use Thread.stop(). But if i don't use it, i don't have any ideas of how stop a thread that i don't control...

  • Firerfox has stopped opening new windows when I ask it to; why is this and what can be done to regain this option?

    Firerfox has stopped opening new windows when I ask it to; why is this and what can be done to regain this option?
    == This happened ==
    Every time Firefox opened
    == not sure - about 2 weeks ago maybe. I recently upgraded to vn 3.6.8

    This is a workstation first off, right? 60 lbs or so?:
    And you have 10.7.2, if not why not?
    Quad core 2.8GHz? 3 x 2GB RAM or more?
    Consider new Mac Pro comes with 1TB drive 50% is actually a lot. Most users off load non system stuff to one of the other 4 hard drive bays.
    As for youtube I do read and saw threads when Lion came out. Lion does not support Rosetta aka PPC/PowerPC code of any kind, plug-ins, drivers and software all. Check into Lion Community?

  • Is there any alternative to Thread.stop();

    Hi everybody,
    I am facing troubles ,while stopping the Thread. at present i am using 'Thread.destroy()', because Thread.stop() was deprecated.#
    Is there any alternative for Thread.Stop()
    Thanks in advance!
    bye

    boolean myThreadShouldRun;
    public void run()
    while (myThreadShouldRun)
    doSomeThing();
    to stop the thread use: myThreadShouldRun=false; from outside the thread and it will stop the natural way. forcing threads to stop with the stop method was dangerous and therefore this method is deprecated and will maybe not be supported in future releases.

  • I go to play on a game on my iPad it will load the game up and a minute later will go to a blank screen and then back to all my apps.does it everybtime? Why is that? What do I need to do to stop it?

    I go to play on a game on my iPad it will load the game up and a minute later will go to a blank screen and then back to all my apps.does it everybtime? Why is that? What do I need to do to stop it?

    1. Close all inactive apps in the Task Bar. Double-click the Home button and hold apps down for a second or two and tap the minus sign to close app.
    2. Try a reset. Hold the Sleep and Home button down for about 10 seconds until you see the Apple Logo

  • What is better way for creating a thread? Why?

    A thread can be create in two way, extending Thread class or implimenting Runnable.
    What is better way for creating a thread? Why?

    Implementing Runnable
    See FAQ #1 here [http://forum.java.sun.com/ann.jspa?annID=9]

  • Replacement for Thread.stop( ) in JDk 1.4

    Hi all,
    Please suggest an alternate solution to this issue.
    1. Thread problem :
    We cannot use System.exit(0) because control goes out of the calling program also.
    We cannot use destroy() because after the Thread.currentThread().destroy(), the program doesnot know how to handle it and it throws up an exception.
    java.lang.NoSuchMethodError
    at java.lang.Thread.destroy(Unknown Source) // also thread.destroy is deprecated
    The other solution that I explored is the use of interrupt(). However, if I try Thread.currentThread.isAlive() , then it returns me TRUE - meaning , that the thread was not killed or stopped. Because of this, the applet does not exit.
    Remaining options:
    Setting the thread to null. Explore more on how to use set the Thread.currentThread to null?
    Applet {
    init{
    new Thread(){
    public void run(){
    }.start();
    exit(){
    Thread.currentThread().stop();
    the focus here has to be what needs to be done to the Thread.currentThread().stop()?
    In case, we cannot find a solution, can we rewrite the applet without Thread.stop() to do the same? Will it exit then? Can you try it?
    Please reply with your suggestions at the earliest.
    Regards
    Abhijeet

    put some while loop in your run() method as follows
    public void run()
    while(flag)
    //do something
    here flag is a boolean variable. Then to stop the running thread, set flag to false from some other thread.

  • What,s the reason to stop iphone 5?? Is there any problem with that phone?? Because still 4s is in market but iphone 5 is stopped.... What,s wrong with apple??

    Why apple stoped iphone 5? What's the reason?? Is there any problem with that phone... Because iphone 4s is still in market.. But they stopped iphone 5.. What's wrong with iphone 5????

    It was replaced by the iPhone 5C, which is essentially the same phone except for the case, better LTE converage and a larger battery.

  • All Application threads stopped for 3~5 minutes

    Hi.
    Our Java application experiences sudden 3~5 minutes application threads stops.
    Our Application is run by 1 process and 300~400 threads.
    All threads are stopped suddenly and are run after 3~5 minutes or more.
    I can't analyze any patten but I experience this problem once or twice a day.
    I guess it is caused by application bug, java bug or Solaris bug and so on.
    I have difficulty to solve this problem and I can't find what causes it.
    Please give advice on this problem.
    (*) Our system :
    SunOS Solaris 5.10 Generic_138888-03 sun4u sparc SUNW,Sun-Fire-V890 (32G Mem)
    (*) Java :
    java version "1.5.0_12"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
    Java HotSpot(TM) Server VM (build 1.5.0_12-b04, mixed mode)
    (*) Java Options
    -mx2048m -Dcom.sun.management.jmxremote.port=16000
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.snmp.interface=`hostname`
    -Dcom.sun.management.snmp.acl=false -Dcom.sun.management.snmp.port=16500 -Xcheck:jni
    -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCApplicationStoppedTime

    Show your GC logs.

  • After upgrading to OX mountain lion my apps store doesn't open. App Store cannot verify a secure connection with the App Store. My internet connection is ok but i don't why this happening. What should i do?

    After upgrading to OX mountain lion my apps store doesn't open. App Store cannot verify a secure connection with the App Store. My internet connection is ok but i don't why this happening. What should i do?

    Hi Tahan007,
    Check these threads out:
    Cannot connect to the App Store since upgrading to Mountain Lion.
    Cannot connect to App Store since 10.8.1
    why is my app store sign in saying connection failed?
    Also if you're running any anti-virus SW, you might try temporarily disabling it

  • About thread stop

    In API, thread.stop() is deprecated.
    If i want to stop a thread, how can i have the same effect like stop()?
    Thanks

    You might also have to call notify() on the thread if it is in a wait() mode.
    - K
    Use a boolean at the top of your run() method:
    boolean bStop = false;
    public void run() {
    if(bStop) return;
    // else do whatever run() is supposed to do
    bStop is a global whish you set depending on
    conditions in your program. If the condition to stop
    the loop becomes true, then you set bStop to true and
    run() will exit.
    Then you can set your reference to the thread to null
    and wait for the GC() to clean up after it. This is
    the recommended way to stop a thread.

  • JDWP fatal error from thread.stop()

    I get this message
    FATAL ERROR in native method: JDWP "util.c" (Jan 20 2004), line 1209: Unexpected error, error code = 113 (JVMDI_ERROR_INTERNAL)
    from the target VM when I do thread.stop() on the debugger side. The debugger isn't bothered by the fatal error, but the target dies.
    Can anyone offer a clue to what I did wrong?
    Peter

    FATAL ERROR in native method: JDWP "util.c" (Jan 20
    2004), line 1209: Unexpected error, error code = 113
    (JVMDI_ERROR_INTERNAL)
    from the target VM when I do thread.stop() on the
    debugger side. The debugger isn't bothered by the
    fatal error, but the target dies.
    Can anyone offer a clue to what I did wrong?Lets see... "Jan 20 2004" implies that you are using the Tiger (1.5)
    beta release for this experiment.
    According to the JDWP spec:
    http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html
    Error 113 is "An unexpected internal error has occurred"
    More information, please...
    - What platform are you running on, and what version(s) of the VM
    are you using?
    - Which thread in the debugee did you send the stop() to?
    - Can you update this article with sample code and a narrative
    describing what happened when?
    - What throwable did you pass to com.sun.jdi.ThreadReference.stop(ObjectReference throwable)

  • KeyStore provider is deprecated, what to use in its place?

    Hi Folks,
    Here (http://edocs.bea.com/wls/docs70/secintro/model.html#1024111), I am
    told that the keystore provider is deprecated.
    Unfortunately, it doesn't tell me why it is deprecated, nor what I should
    use in its place.
    I still need it to store the private keys used in the SSL configuration, so
    why is it deprecated?
    Regards,
    Jon

    "Jon Mountjoy" <[email protected]> wrote in message
    news:[email protected]..
    Hi Folks,
    Here (http://edocs.bea.com/wls/docs70/secintro/model.html#1024111), I am
    told that the keystore provider is deprecated.
    Unfortunately, it doesn't tell me why it is deprecated, nor what I should
    use in its place.
    I still need it to store the private keys used in the SSL configuration,so
    why is it deprecated?
    In 8.1, we added keystores to the server mbean. Having a provider to
    configure
    the keystore information was limiting as it required all servers in the
    domain to
    have the same keystore filename (since keystore providers are configured
    on the realm and there is one realm in the domain).
    You can continue to use the keystore providers in 7.0. We just didn't want
    anyone writing their own providers.
    Regards,
    Jon

  • My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    I have worked my way through the assistant and nothing works. I have tried connecting in disc mode but although the screen on the ipod is showing that the device is charged and that it is in disc mode as soon as I connect it to the computer it comes up with the error message 'please wait very low battery' and stays like that until I disconnect when it appears to be OK again. I have tried on both pc and mac.
    BTW the ipod is an ipod video not classic if that makes any difference.
    Thanks

  • My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    I was having this problem while still using Mavericks -- it started after a Mavericks update last spring.  During the initial Yosemite beta runs over the summer, it seemed to be fixed, but after the official launch in October, I had all sorts of problems keeping connected.  Its gotten a little better, but still happens to at least one of my devices every day.  Weird that we still cannot figure out why the connection keeps dropping on some devices, but not others, and then the next day, one of the devices that didn't disconnect the previous day will disconnect, but the ones that did disconnect, stay connected.  It's just sloppy, poorly written software for technology that isn't working the way it should.  If you turn off Continuity and Handoff on all your devices, you will probably see that everything stays connected.  With those turned off on all devices, TC stayed connected to everything for over a month.  The day I turned Continuity back on, all the problems started again.  It had something to do with the bluetooth version being used, the wifi routine, and Apple's AirPlay technology not quite getting along with each other.

Maybe you are looking for

  • V_NL Net price list

    Hi All, Can anybody explain the excact functionality V_NL, and what are all the restrictions it has? What are the default feilds refers to, Event there is bundle of data is available but not getting any thing in output?...... Thanks in advance.... Ra

  • Julian Convert

    Hi all. I have Julian dates in my database I want to convert it to date type. How can I do it? Thank you very much...

  • Over-asked question

    okay, so intially I registered my ipod on my PC at home. I now have a laptop. I realize it's possible to plug in my ipod and listen to music, but is it possible to import my songs from my ipod on to my itunes on the laptop--keeping in mind that this

  • Problems with internal memory

    Hello people, I have a problem with my iPhone. If I go to Usage window in my settings, it says "4.2GB used". However, if I count all MB's of the apps listed below, I don't even get near 4.2GB. It's about 1.3. How is this possible? I know the OS needs

  • Why can't I sign into the App Store?

    When I try to Sign In into the App Store, it always says that my Apple ID has never been used in the App Store before and that I have to review my information. When I click Review it leads me to create ANOTHER Apple ID! What should I do?