Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. private Thread timeout_request = new Thread(new Runnable() {
  2. public void run() {
  3. try{
  4. Log.d(TAG, "Thread start");
  5. Thread.sleep(30000);
  6. Log.d(TAG, "Thread awake");
  7. if(!httprequest_finished){
  8. request_aborted = true;
  9. mHttpClient.getConnectionManager().shutdown();
  10. }
  11. }catch(Exception e){
  12. e.printStackTrace();
  13. }
  14. }
  15. });
  16.  
  17. public String sendData(String token){
  18. ...
  19. timeout_request.start();
  20. Log.i(TAG, "Sending request");
  21. final HttpResponse resp = httpClient.execute(post);
  22. Log.i(TAG, "Execute finished");
  23. if(request_aborted) return null;
  24. httprequest_finished = true;
  25. ...
  26. }
  27.  
  28. private Handler mHandler = new Handler();
  29. private Runnable r = new Runnable() {
  30. public void run() {
  31. Log.d(TAG, "Runnable()");
  32. if(!httprequest_finished){
  33. request_aborted = true;
  34. mHttpClient.getConnectionManager().shutdown();
  35. }
  36. }
  37. };
  38.  
  39. threadid=3: reacting to signal 3
  40. Wrote stack traces to '/data/anr/traces.txt'
  41. threadid=3: reacting to signal 3
  42. Wrote stack traces to '/data/anr/traces.txt'
  43.  
  44. Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
  45. public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
  46. Log.e("Alert","Lets See if it Works !!!");
  47. }
  48. });
  49.  
  50. /*
  51. * To change this template, choose Tools | Templates
  52. * and open the template in the editor.
  53. */
  54. package javaapplication1;
  55.  
  56. /**
  57. *
  58. * @author paro
  59. */
  60. public class JavaApplication1 {
  61.  
  62. public boolean req_aborted = false;
  63. public Thread timeout_request = new Thread(new Runnable() {
  64. public void run() {
  65. try{
  66. System.out.println("start");
  67. Thread.sleep(30000);
  68. System.out.println("awake");
  69. if(req_aborted ==false)
  70. {
  71. req_aborted = true;
  72. System.out.println("flag change");
  73. }
  74. }catch(Exception e){
  75. e.printStackTrace();
  76. }
  77. }
  78. });
  79. /**
  80. * @param args the command line arguments
  81. */
  82. public static void main(String[] args) {
  83. // TODO code application logic here
  84. JavaApplication1 jap = new JavaApplication1();
  85. jap.timeout_request.start();
  86. System.out.println("requset started");
  87. if(jap.req_aborted)
  88. {
  89. System.out.println("flag is true now");
  90. }
  91. }
  92. }
  93.  
  94. requset started
  95. start
  96. awake
  97. flag change
  98.  
  99. final HttpResponse resp = httpClient.execute(post);
  100.  
  101. Handler mHandler = new Handler();
  102. ...
  103. mhandler.postDelayed(new Runnable() {
  104. public void run() {
  105. if(!httprequest_finished){
  106. request_aborted = true;
  107. mHttpClient.getConnectionManager().shutdown();
  108. }
  109. }
  110. }, 30000);
  111.  
  112. response.getStatusLine().getStatusCode()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement