em có 1 thread xử lý như sau :
while (true) { System.out.println("3"); Thread.sleep(1000); }
Làm thế nào để thu hồi thread này vậy ạ
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Khả năng là không có cách nào em ạ. Anh đã thử interrupt nhưng không được:
em cảm ơn anh, vậy nếu rơi vòng lặp vô hạn thì server đó mất luôn 1 thread đó. Giả sử server có 16 thread chỉ cần gọi 16 lần là server phải restart lại ạ
1. Anh cũng không rõ 1 server có tối đa bao nhiêu thread, tuy nhiên trong java mỗi thread chiếm đâu đó khoảng 2MB bộ nhớ nên nếu quá nhiều thread sẽ dẫn đến tốn bộ nhớ không cần thiết.
2. Còn giả sử server có tối đa 16 thread thì không có nghĩa là chỉ cần gọi 16 lần là server sẽ phải restart, có thể sẽ chỉ đơn giản là thread thứ 17 sẽ không được tạo ra, nói chung anh chưa bao giờ tạo đến một số lượng max thread nên cũng không rõ em ạ. Một server anh tạo thường rất nhiều thread, thường sẽ là vài chục thread là đủ.