Deprecated Thread Methods

My organization has recently come from the Microsoft world into the J2EE world. In .Net, Microsoft has an abort method on threads that is similar to the Java's stop method. Unfortunately, the stop method has been deprecated.
While I have read the information on why this method is dangerous, I don't understand why the method has been removed. If I have a situation that warrants killing a thread (such as in the case of an application server that hosts other threads of execution), why remove it from the platform? While I agree with Sun's article on seeking out alternative methods, there are still exceptions where a thread just needs to be interrupted so that it can get out of a deadlock, endless loop or blocking I/O.
Since the stop method is deprecated, is there an equivalent VM call that I can interface from native code?
I must say that I feel a bit like I'm being mothered by Sun.

From your comments, you make a strong argument that suggests there's no need for a VM-level stop function.
This puzzles me because operating systems implement kill methods to terminate rogue processes, yet they remain efficient and manage to keep things clean. Granted, multiple processes don't generally share memory structures but certainly the OS, on their behalf, shares memory structures. I'm puzzled as to why similar desires/features aren't present in the JRE.
Regardless, short of running multiple JRE instances, each managing just one piece of work, the current deprecated status of the stop method renders Java without the ability to stop something that's gone wild unless the application is specifically pre-programmed to anticipate this behavior. (Of course that's a bit of a catch 22 in and of itself but...)
There is also a subscription to the notion that my company or company x can write perfect software that never hangs a Java-based application server. I feel that this is impractical -- especially when what businesses ask of IT continues to get more complex.
At this point perhaps it's fair to reveal the underlying reasons for my up-to-now, hypothetical questions. In my situation, company x is actually Sun. They failed to expose a socket timeout on their implementation of HTTPUrlConnection. I suppose that pretty much removes the luster from the argument that I, or anyone else, can write perfect software when the inventors of Java are themselves, imperfect. Of course, like you said and the JDK documents, the stop method will not abort a blocking socket read anyway (...although there's no reason why it couldn't except for more flawed design decisions...)
I've certainly investigated alternative packages but I'm just chasing a moving target. HTTPUrlConnection today, class x tomorrow. That's why I was wanting something at the framework level to provide a trap door so that recovery without terminating the JRE is possible.

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...

  • Declare deprecated a method

    Hello,
    I need to declare deprecated a method into my classes and simply I don't know how. I've tried to use a javadoc comment @deprecated but after I compile I don't receive the message that this method is deprecated.
    Thanx

    Check "What happens when an API is Deprecated"
    http://java.sun.com/products/jdk/1.1/docs/guide/misc/deprecation/deprecation.html
    and read the note, that says if you compile the class with the deprecated method along with classes that uses this method, then you won't get a warning. :)

  • Start Thread method behaviour

    I'm using Oracle 10
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining optionsI created two Java classes and a wrapper procedure.
    1. The first class timeOutSAPEntry has a delay caused by sleep method of 10 sec. then updates a row in table sap_entry.
    2. The second class createMonitorSAPEntry creates an instance of timeOutSAPEntry, call start() method and ends.
    3. And the wrapper procedure just calls createMonitorSAPEntry.
    My problem: when I call the wrapper procedure, it hangs for 10 sec (consequence of sleep method). But, I expected that the thread could be created, started and then the control returns to procedure and finishes immediatelly. You can see in the execution below the sysdate before and after the procedure call.
    Is there any solution? I would like the same behaviour of others JVM, where the main thread continues the execution and not hangs out waiting for the started thread.
    create or replace
           and compile java source named "timeOutSAPEntry"
    as
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    public class timeOutSAPEntry
        extends Thread{
        public void run(){
            try{
                 this.sleep(10000);
                 Connection conn =
                        DriverManager.getConnection("jdbc:default:connection:");
                 PreparedStatement  st = conn.prepareStatement("update cmforna.sap_entry set status = 'Failed' where Status = 'Sent'");
                 st.executeUpdate();
                 st.close();
                 conn.commit();
                 conn.close();      
            }catch(Exception e){
                e.printStackTrace();
    create or replace
           and compile java source named "createMonitorSAPEntry"
    as
    public class createMonitorSAPEntry{
       public static void create(){
            timeOutSAPEntry to = new timeOutSAPEntry();
            to.start();
    create or replace procedure create_monitor_post
    as
    language java name 'createMonitorSAPEntry.create()';
    SQL> insert into sap_entry
      2  (id, posted_on, status)
      3  values
      4  (6, sysdate, 'Sent');
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select to_char(sysdate, 'hh24:mi:ss') Before_Time from dual;
    BEFORE_T
    16:27:04
    SQL>
    SQL> exec create_monitor_post;
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select to_char(sysdate, 'hh24:mi:ss') After_Time from dual;
    AFTER_TI
    16:27:14
    SQL> Many tks,
    Miguel

    Add a KeyAdapter like this:
    addKeyListener(new KeyAdapter() {
      public void keyPressed(KeyEvent ke) {
        int key = ke.getKeyCode();
        if (key == KeyEvent.VK_LEFT) x1--;
        if (key == KeyEvent.VK_RIGHT) x1++;
    });*Note that I added this just after the bouncing = true; ... which is on about line 33.
    **Note that you will need to click in the Applet before the keys will function.
    ***Note that you will also likely want to slow down the balls.
    ~Bill

  • Thread Methods but in Object class, y?

    Why wait, notify, notifyall methods are in object class instead of Thread class?

    thechad wrote:
    It's not clear to me why. Probably it's a historical artefact .. once it was in Object, it's hard to take it out.
    You're question is a fair question it seems to me. Maybe someone will tell you there's a good reason.Yes, there is a very good reason and it's not a historical artifact.
    wait / notify are used for locking in java. For instance, imagine you have a job queue, and you've got a whole bunch of worker threads that are getting jobs from it. What happens when the queue is empty and there are no more jobs? You want to wait for the queue to have more jobs. Then when a new job comes in, you want to notify any thread waiting that it can now proceed.
    In fact, with reference to why isn't this just handled in thread, it is dangerous and wrong to call wait, notify or notifyall on a Thread object... Thread.join calls wait on the thread and thread death calls notifyAll, but API docs don't guarentee this so you should avoid these methods in a Thread object.

  • I need a solution for the deprecated readLine() method .

    import java.io.*;
    import java.net.*;
    class UC {
    public static void main(String args[]) throws Exception
    DataInputStream inFromUser = new DataInputStream(System.in);
    DatagramSocket clientSocket = new DatagramSocket();
    InetAddress IPAddress = InetAddress.getByName("hostname");
    byte[] sendData = new byte[1024];
    byte[] receiveData = new byte[1024];
    while(true)
    String[] sentence = inFromUser.readLine(); /* It says the readLine() method is deprecated. what is the solution for this? */
              sentence.getSubstringBytes(sentence,0, sentence.length(), sendData, 0);
    //sentence.getBytes(0, sentence.length(), sendData, 0);
    DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
    clientSocket.send(sendPacket);
    DatagramPacket receivePacket
    = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.receive(receivePacket);
    String modifiedSentence =
    new String(receivePacket.getData());
    System.out.println("FROM SERVER:" + modifiedSentence);
         public void getSubstringBytes(String sentence,int space,int Size,byte[] sendData,int space)
                   byte[] bytes=sentence.getBytes();
                   System.arraycopy(bytes,0,sendData,0,sentence.length()-0);
    }

    Sorry, It should be the BufferedReader , not BufferedInputStream.

  • Threads & Methods

    hi,
    i have question.... when you call a method ... then are you creating a
    new Process........ or in other words : is
    calling a method = creating a new process
    just curious

    answer = no
    A thread represents a flow of execution - when you call a method the same thread is used to run that method. When that method is finished the thread continues from where it was in the calling method.
    I'm surprised you're asking this question given your areas of expertise. Perhaps I've misunderstood what you mean?
    Hope this helps.

  • Best thread method for a chat server

    What would be the best way to thread a chat server in Java? I understand threads, but I'm new to java. I'm just looking for links to the appropriate classes not code. I already have the send/receive methods planed, but I'm interested in the best ways to pool the clients once connected.

    class: Thread
    interface: Runnable
    The two items above are what you need.

  • PDFDocMerger API Deprecated mergePDFDocs Method

    All,
    We are trying to use the supplied PDFDocMerger API and running into some issues. When I look at the documentation it states that the mergePDFDocs method is deprecated; I do not see a replacement method. Is the documentation lacking updates and there is a new method to use or does the API simply not work anymore? I would really appreciate any insight into this issue as I need to merge PDFs and don't want to go outside the supplied API's.
    Thanks in Advance,
    Josh

    Ok, just looked over the documentation one more time and realized process() replaces it.
    Edited by: user11201963 on Aug 7, 2009 9:25 AM

  • Deprecated methods

    The following method has been deprecated. Does anyone know what it is replaced with? Also, is there a list of what has been deprecated and what the replacement method is and how to implement the replacement method?
    •     Warning(1886,24): setSelectedItemToStringConverter(oracle.bali.inspector.editor.ToStringConverter) in oracle.bali.inspector.PropertyEditorFactory2 has been deprecated
    Thanks

    Hi,
    such documentation should be part of the JavaDoc unless the developer deprecating the method forgot to mention it. There is no other documentation than that to provide the information. The JavaDocs say:
    * @deprecated use {@link #setEditorComponentInfo(EditorComponentInfo)} instead.
    So its in the same class
    Frank
    ps.: Hope you know what you do because I am not sure bali classes are open for public consumption

  • Thread.run() method..

    I was wondering how the "Thread.run()" method get called. I started with "Thread.start()" and found it calls the "Thread.start0()" which is a native method.
    I downloaded the JDK 5 source code and went to "j2se\src\share\native\java\lang\Thread.c". In "Thread.c" I found a mapping of "start0()" with "JVM_StartThread".
    After that I opened the "hotspot\src\share\vm\prims\jvm.cpp". From line no 2257 to 2316 I saw the implementation of "JVM_StartThread".
    In side "JVM_StartThread", I saw there is a call to "Thread::start(native_thread)" and opened the "hotspot\src\share\vm\runtime\Thread.cpp". In "Thread.start()" method there is a call to "os::start_thread(thread);".
    In "hotspot\src\share\vm\runtime\os.cpp" the "os::start_thread()" calls the "pd_start_thread(thread);" method. But I did not get the "pd_start_thread(thread);" method in os.cpp.
    Note: I am java programmer and hardly understand the C/C++ languages. But had a doubt how the run() method get called and how the Thread.start() method works. But I got stuck here.
    Kindly help me to know how the flow goes, when we call the Thread.start() and how the run() method is linked to it.

    But I did not see anything in the os.cpp. In fact i did not find the "pd_start_thread(thread);" .
    void os::start_thread(Thread* thread) {
      // guard suspend/resume
      MutexLockerEx ml(thread->SR_lock(), Mutex::_no_safepoint_check_flag);
      assert(thread->is_baby_thread(), "thread has started");
      thread->clear_is_baby_thread();
      OSThread* osthread = thread->osthread();
      // A thread may be suspended in the presence of the profiler.
      // Only start thread when it's not suspended.
      osthread->set_state(RUNNABLE);
      if (!thread->is_vm_suspended()) {
        pd_start_thread(thread);
    }

  • How to Diasble JLabel since enable(false) method is deprecated in jdk1.4

    Hi friends
    i am using jdk1.4 in which enable method is deprecated.
    i am disabling my jlabel using jlabel.enable(false); method
    however this is deprecated.
    what method should i then use
    please do help

    You just try with the .setEnabled(false); This will
    help to solve your problem.Hey Thanks Mr. Sumode , its working with .setEnabled(false);

  • Method Session session.connection() is deprecated - version 1.6

    hi, making migration 1.4 to 1.6 version JDK, the method session.connection() is deprecated, by what method or feature you can run the code without deprecation
    a method which is used:
    public void saveFinding(DasFinding finding) {
    if (finding.getId() == null) {
    Long sequenceNumber = (Long) getSession().createQuery("select count(*) from DasFinding f where f.das = :das").setParameter("das", finding.getDas()).setFlushMode(FlushMode.COMMIT).uniqueResult();
    finding.setSequenceNumber(sequenceNumber.intValue() + 1);
    if (finding.getStatus().equals(FindingStatus.CLONE)) {
    finding.setStatus(FindingStatus.OPEN);
    Session hibernateSession = getHibernateTemplate().getSessionFactory().getCurrentSession();
              hibernateSession.setFlushMode(FlushMode.ALWAYS);
              hibernateSession.saveOrUpdate(finding);
              hibernateSession.flush();
              if (finding.getDescription() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_DAS_FINDING", "DESCRIPTION", "DAS_FINDING_ID", finding.getId(), finding
                                  .getDescription(), hibernateSession.connection());                     
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Summary '" + finding.getDescription() + "'(" + finding.getId()
                                  + ") " + "\nException : " + e.getClass().getName() + " Message(s): " + e.getMessage() + " "
                                  + e.getLocalizedMessage());
                        e.printStackTrace();
                   hibernateSession.refresh(finding);
    another method which is used:
    public void saveFindingComment(DasFindingComment comment) {
    if (comment.getId() == null) {
    Long sequenceNumber = (Long) getSession().createQuery("select count(*) from DasFindingComment f where f.finding = :finding").setParameter("finding", comment.getFinding()).setFlushMode(FlushMode.COMMIT).uniqueResult();
    comment.setSequenceNumber(sequenceNumber.intValue() + 1);
    Session hibernateSession = getHibernateTemplate().getSessionFactory().getCurrentSession();
              hibernateSession.setFlushMode(FlushMode.ALWAYS);
              hibernateSession.saveOrUpdate(comment);
              hibernateSession.flush();
              if (comment.getSummaryPosCommission() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_DAS_FINDING_COMMENT", "SUMMARY_POS_COMMISSION",
                                  "DAS_FINDING_COMMENT_ID", comment.getId(), comment.getSummaryPosCommission(), hibernateSession.connection());
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Commission Position Summary '"
                                  + comment.getSummaryPosCommission() + "'(" + comment.getId() + ") of finding "
                                  + comment.getFinding().getId() + "\nException : " + e.getClass().getName() + " Message(s): "
                                  + e.getMessage() + " " + e.getLocalizedMessage());
                        e.printStackTrace();
              if (comment.getSummaryPosCountry() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_DAS_FINDING_COMMENT", "SUMMARYPOSCOUNTRY", "DAS_FINDING_COMMENT_ID",
                                  comment.getId(), comment.getSummaryPosCountry(), hibernateSession.connection());
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Country Position Summary '" + comment.getSummaryPosCountry()
                                  + "'(" + comment.getId() + ") of finding " + comment.getFinding().getId() + "\nException : "
                                  + e.getClass().getName() + " Message(s): " + e.getMessage() + " " + e.getLocalizedMessage());
                        e.printStackTrace();
    * deleteFindingComment
    * @param comment DasFindingComment
    a another:
    public void saveFindingComment(DasFindingComment comment) {
    if (comment.getId() == null) {
    Long sequenceNumber = (Long) getSession().createQuery("select count(*) from DasFindingComment f where f.finding = :finding").setParameter("finding", comment.getFinding()).setFlushMode(FlushMode.COMMIT).uniqueResult();
    comment.setSequenceNumber(sequenceNumber.intValue() + 1);
    Session hibernateSession = getHibernateTemplate().getSessionFactory().getCurrentSession();
              hibernateSession.setFlushMode(FlushMode.ALWAYS);
              hibernateSession.saveOrUpdate(comment);
              hibernateSession.flush();
              if (comment.getSummaryPosCommission() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_DAS_FINDING_COMMENT", "SUMMARY_POS_COMMISSION",
                                  "DAS_FINDING_COMMENT_ID", comment.getId(), comment.getSummaryPosCommission(), hibernateSession.connection());
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Commission Position Summary '"
                                  + comment.getSummaryPosCommission() + "'(" + comment.getId() + ") of finding "
                                  + comment.getFinding().getId() + "\nException : " + e.getClass().getName() + " Message(s): "
                                  + e.getMessage() + " " + e.getLocalizedMessage());
                        e.printStackTrace();
              if (comment.getSummaryPosCountry() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_DAS_FINDING_COMMENT", "SUMMARYPOSCOUNTRY", "DAS_FINDING_COMMENT_ID",
                                  comment.getId(), comment.getSummaryPosCountry(), hibernateSession.connection());
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Country Position Summary '" + comment.getSummaryPosCountry()
                                  + "'(" + comment.getId() + ") of finding " + comment.getFinding().getId() + "\nException : "
                                  + e.getClass().getName() + " Message(s): " + e.getMessage() + " " + e.getLocalizedMessage());
                        e.printStackTrace();
    * deleteFindingComment
    * @param comment DasFindingComment
    thanks in advance

    I'am sorry for not using the tags, I wrote quickly, thanks.
    Yes, new version of Hibernate, until today, 3.3.0, hibernate3.jar, don't have replace the metod connection,
    P:S:
    www.hibernate.org recommend using the SPI or DoWork(),
    "Session.connection()" is used in lines of code below:
    public void saveFinding(Finding finding) {
    if (finding.getId() == null) {
    // hibernate 3.2.6 uniqueresult is now int64 => Long
    Long sequenceNumber= (Long)getSession().createQuery("select count(*) from Finding f where f.mission = :mission").setParameter("mission", finding.getMission()).setFlushMode(FlushMode.COMMIT).uniqueResult();
    finding.setSequenceNumber(sequenceNumber.intValue() + 1);
    // CR 1266
    // if the finding status is CLONE, change it to OPEN
    if (finding.getStatus().equals(FindingStatus.CLONE)) {
    finding.setStatus(FindingStatus.OPEN);
    Session hibernateSession = getHibernateTemplate().getSessionFactory().getCurrentSession();
              hibernateSession.setFlushMode(FlushMode.ALWAYS);
              hibernateSession.saveOrUpdate(finding);
              hibernateSession.flush();
    if (finding.getDescription() != null) {
                   try {
                        ClobSolver.insertClobString("AUD_FINDINGS", "DESCRIPTION", "FINDING_ID", finding.getId(), finding
                                  .getDescription(), hibernateSession.connection());
                   } catch (Exception e) {
                        log.error("Comments CLOB not saved for Summary '" + finding.getDescription() + "'(" + finding.getId()
                                  + ") " + "\nException : " + e.getClass().getName() + " Message(s): " + e.getMessage() + " "
                                  + e.getLocalizedMessage());
                        e.printStackTrace();
                   hibernateSession.refresh(finding);
    you can replicate the functionality
    thank you

  • Difference between LockSupport.parkUntil and Thread.sleep method

    Hi
    Could someone please explain the difference between LockSupport.parkUntil and Thread.sleep methods.
    Thanks in advance.

    javaLearner wrote:
    The thing that I am trying to understand is - the difference / correlation between the two methods mentioned.
    In the javadoc, there is a mention of correlation between the LockSupport methods park, unpark and the Thread methods suspend, resume - but not park and sleep.Then that suggests that there isn't any difference /correlation -- whatever you meant by that. Perhaps your question is like asking for the difference between a fish and a bicycle.
    Also, I would like to understand the statement
    These methods are designed to be used as tools for creating higher-level synchronization utilities, and are not in themselves useful for most concurrency control applications. (from the javadoc)Again, you're going to have to explain what you don't understand about it.

  • How to stop a thread in java 1.5 on windows

    Hi All,
    I am using Java 1.5 on windows plateform. I want to stop all the threads which belongs to a particular process when the timeout occurs. In java 1.5 stop() method is depricated and interrupt method just sets the flag and does not stop the thread actually.
    Is there any way to destroy the thread permenently. I am using TheadPool Executor class.
    Regards
    Rinku Garg

    Hi,
    I am having a timer task which is scheduled to run after some fixed time interval when the process started.
    Now this timer task when started, should destroy the active threads of the request. When the request is timed out then the thread is action should termininate.
    In my case run method of particular thread had already made a call to Database through DAO when the time out occurs. So how can I set up a loop in run method which I found on google.
    thread.stop() is deprecated.
    thread.destroy() is deprecated.
    I used thread.interrupt() but it does not stops the thread.
    Please help me in this scenario.
    Regards
    Rinku Garg

Maybe you are looking for

  • Last payment information Report

    Hi All I am looking for assistance with a report. Our auditors are looking for a report that will show, by vendor and company code, the last bank account that a payment was made too, for a date range that must be entered when the user runs the report

  • Help with decode

    Let's call the field "xfieldx". It's currently a char data type that either gets inputted as null or "y" meaning yes. The problem comes when the query counts the number of rows that have a non-null value. The sql is below sum(decode(xfieldx, null, 0,

  • Iphoto Metric/US

    How do I change the photo sizes from inches to cm in the new iPhoto share/print? I've already checked Settings/languages and regions, It's on the metrik system, but i still get US measurements used when i want to print a photo?

  • What is the best way to Insert BLOB in DB?

    Hi, We are having a Table containing BLOB datatype & trying to populate it using JDBC. But simple insert is not allowing us to insert the data into table. As the alternative we used to firstly insert a empty_blob & later on update it using FOR UPDATE

  • WAS java install hangs when tries to start engine

    I am trying to install a WAS 640 JAVA I recently deleted and installation off of this server, I dont know if this has anything to do with my problem. When the new install reaches the last step of starting the J2ee it hangs. WHat happens is it starts