2014年5月22日星期四

Neighborhoods, multithreading in javaweb application

After learning the java multithreading , for some simple examples to know how a simple thing, but so far not used in web development multi-threading technology. So there are some doubts as listed below:
1.web applications to use for a particular task multithreading , the most simple code format is not necessary to run the code to be executed on the method ?
2. deploy a Web site on a server , multiple browser when accessing the same function point , there are multiple threads of saying?
3 and more . between threads and concurrency is how a relationship ?
4. tickets for classical procedures , because they want to co- operate with multi-threading technology resources, but then for some of the usual queries display no need to use multi-threading technology. For multiple query initiated here , a plurality of thread do ?
Daniel answers you seek , these questions have puzzled me ! ! !

------ Solution ------------------------------------ --------
deployed on the server a site in multiple browsers to access the same function point , it is said there are multiple threads
exist. Only http server package to help you better
------ Solution --------------------------- -----------------
direct new one thread are generally anonymous class implements the run method , so that you can achieve a multi-threaded
------ Solution - -------------------------------------------
last question - - the presence of concurrent operations on shared resources , you have to use multiple threads, so I understand the
------ Solution - -------------------------------------------
1.web applications , to use for a particular task multithreading , the most simple code format is not necessary to run the code to be executed on the method ?
WEB server will help you to open up a thread for each access request , as long as you follow the framework developed by you , such as tomcat servlet will let you take advantage of this framework to write code. Specifically really hard to describe , without written RUN anyway , unless you want to thread control to the extreme , such as you do the test .
2. deploy a Web site on a server , multiple browser when accessing the same function point , there are multiple threads of saying?
multiple browsers mean if it is ( on either the same or multiple computers on a computer ) features multiple pages open a page on the same site , then as the first question said , every visit ( that opens the page ) is a request, the server will open up a thread for each request , is multi-threaded .
3 and more . between threads and concurrency is how a relationship ?
multithreaded concurrent execution efficiency is judged good or bad , the concept is in high concurrency situations to ensure data accuracy and reduce the time required for the operation of the process , especially after the classic page to access the server , allowing the server to modify database, if your database optimization done in place, then find the data and return to the client 's time will be greatly reduced, we know that the query volume of a popular site is very large, the number of processes and a server memory that can be received is limited , this way , we say that a certain period of time processing threads ( access request ) , the more so the better the concurrent efficiency .
4. tickets for classical procedures , because they want to co- operate with multi-threading technology resources, but then for some of the usual queries display no need to use multi-threading technology. For multiple query initiated here , a plurality of thread do ?
buying program and WEB application should be multi-threaded, common resources stored in the database , and answer the third question similar to this commercial site is more focused on ensuring data accuracy , and sometimes we modify the particular value will affect other people's queries and deletions , so unexpected situation arises, for example, in an a thread ( user ) is modifying a value ( buying ) the circumstances, to reduce the amount of residual votes 1 is not accurate , because when the user remaining in the method of the total number of votes obtained at the same time ( to get the total remaining number of votes , but not yet minus one ) , another B threads ( users ) also buy a ticket, then B obtained a total remaining votes and the same , so if they are allowed to operate while the database of public resources , then when they both want the operation finished ticket minus one third the amount of thread or check other threads remaining tickets will only be will see the reduction of two remaining original amount , less a reality only conceivable if the thread operations , the more errors will be greater. Therefore, the database will have affairs , locks , etc. to ensure concurrency concept to improve the efficiency of data accuracy under the premise
------ For reference only ---------------- -----------------------
like this one, 4th floor talk in great detail .


没有评论:

发表评论