); System.out.println (Thread.CurrentThread (). GetName ()+ "has a put num:" +num); //A, b objects Get values by CurrentThread NewA (). get (); NewB (). get (); }}). Start (); } } //A object outputs the data for NUM in the current thread Static classa{ Public voidget () {System.out.println (Thread.CurrentThread (). GetName ()+ "has a num---A:" +Map.get (Thread.CurrentThread ())); } } //the B object outputs the data for NUM in the current threa
Content from, Zhang Xiaoxiang teacher's Zhang Xiaoxiang-java multi-threading and concurrent Library Advanced Application Video tutorialPackage Com.lipeng;public class MyThreadLocalTest2 {private final static mythreadlocalJava Multi-Threading and concurrency Applications-(5)-How to use the Threadlocal class gracefully
the volatile modifier, all operations on this variable are atomic, and when the value of the variable is determined by its own previous decision, such as N=n+1, n++, the volatile keyword will fail, The operation of the variable is atomic if it is independent of its previous value, such as n = m + 1, which is the original level. So in the use of volatile key must be cautious, if they are not sure, you can use synchronized to replace volatile.
To solve this problem, there are two options:1, the t
the service method to complete the modification * 3. Save the success message to request domain * 4. Forward to msg.jsp display success Information *///has encapsulated the CID into the Customer object in customer c = Commonutils.tobean (Request.getparametermap (), Customer.class) ; Customerservice.edit (c); Request.setattribute ("msg", "Congratulations, edit Customer success!") "); return" f:/msg.jsp ";} Public String Query (httpservletrequest request, httpservletresponse response) throws Serv
The Threadlocal object helps us to manage the objects within the thread, ensuring that the objects are isolated from each other.The pit we met today is like this:Index01.html page load will be sent once a request, and then click on the attachment upload will send an upload request B, upload success will send a download request C,Where a request passes through the Interceptor01 Interceptor, the Interceptor01 internally passes the Module_name parameter
emulate the Threadlocal class implementation : Thread-scoped shared variables, each thread can only access his own, and cannot access other threads. PackageCom.ljq.test.thread;ImportJava.util.HashMap;ImportJava.util.Map;ImportJava.util.Random;/*** thread-wide Shared variables * * Three modules shared data, main thread module and AB module *@authorAdministrator **/ Public classThreadscopesharedata {//prepare the shared data Private Static intdata =
Oom?Java.lang.OutOfMemoryError:java head space heap memory overflowJava.lang.OutOfMemoryError:Permgen Space Java Eternal Overflow, that is, methods to overflow, generally because of the emergence of a large number of classes and JSPs, or the use of Cglib reflection mechanism,This can be resolved by changing the size of the method area and modifying it in the form of a similar-xx:permsize=64m-xx:maxpermsize=256m. In addition, too many constants, especially strings, can cause the method area to ov
In multi-threading, locking is required for operations that share data in common.However, for local variables , each thread is independent of each other.If the thread t want to F1 the function in the local variable V1 to the function F2, F2 again want to put this variable to F3, a layer of a layer of the more cumbersome to pass.Name the object returned by Python's threading.local () tl, place the TL at the Global location, and bind the properties to the TL in each function.TL can be regarded as
Database connection and STRUT2 for each request threadlocalImport java.util.random;public class threadlocaltest { private static ThreadLocal x = new ThreadLocal ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.