tailieunhanh - peer-topeer Networks phần 5

Lưu ý rằng điều quan trọng là để phân biệt sự khác nhau giữa getNextNumber () và getTaskNumber () phương pháp. GetNextNumber () trả về số lượng công việc phụ kế tiếp có sẵn, nhưng nhiệm vụ phụ không được giao chủ đề nào được nêu ra. | 100 8. Testing and Enhancements of Servlets import . import . import . public class home extends HttpServlet String GlobalFile String LocalFile public void init throws ServletException home program started ServletConfig cfg getServletConfig LocalFile FileName Local value LocalFile ServletContext global getServletContext GlobalFile global Global value GlobalFile public void doGet HttpServletRequest request HttpServletResponse response throws ServletException IOException PrintWriter output html head title home title head body h1 Globle File GlobalFile br Local File LocalFile h1 body html end of method public void destroy destroy method of home called Figure . Synchronization 101 Figure . Screen of browser Figure . Screen of server Synchronization A web server creates a thread of the servlet to handle a browser s request. Multiple threads can be created at the same time. The advantage is that the creation of threads is handled automatically by the server. We do not need to code it in the servlet. On the other hand this feature could be a problem for some applications. Let us consider the following examples A client sends a number to the servlet. The servlet adds the number to the variable sum . The value of sum might not be correct if we allow multiple threads to update the variable sum at the same time. Locking mechanism is required and it can be achieved by synchronization. Syntax of the synchronization is public class ExampleServelt extends HttpServlet Declare your variable here . sum public void init throws ServletException 102 8. Testing and .

TỪ KHÓA LIÊN QUAN