The first step is to find out the Java process PID: Grep-v "awk ' {print $2} ' The second step is to find the most CPU -Consuming threads : PS-MP pid-o Thread,tid,sort-rn-k9The third step is to convert the TID to a three- input system : printf "%x\n" tidThe fourth step is to dump the JVM stack information : Jstack PIDthe NID in jstack corresponds to the preceding octal tid, thus finding the most CPU-consuming thread code. To get a thread usi
Versions earlier than Java 7 do not have native support. Let's talk about the solution of JDK 1.7 and earlier:Event-driven approach, without having to perform directory scans, but related to the platformThread round-robin scanning, implemented in java only, perfect cross-platform, but with a large number of listening files, the scanning volume is too large, and the response is not very timely, depending
intWatchid = Jnotify.addwatch (path, mask, Watchsubtree,NewListener ()); //sleep a little, the application would exit if you//don ' t (watching is asynchronous), depending on your//application, this could not be requiredThread.Sleep (1000000); //To remove watch the watch Booleanres =Jnotify.removewatch (Watchid); if(!Res) { //Invalid watch ID specified. } } classListenerImplementsJnotifylistener { Public voidFilerenamed (intWD, String RootPath, String oldna
", Baseutil.getextensionstate (Extensionstatus.getstatus ()));New WebSocket (). Broadcastall (Jsono);Call hold event for the time being}else if (event instanceof Parkedcallevent) {Parkedcallevent parkcall= (parkedcallevent) event;String Key=baseutil.getnumber (Parkcall.getfrom ());Key+=baseutil.channelpark_centent;Mapcache.put (Key, Parkcall.getexten ());Get Database Data Events}else if (event instanceof Dbgetresponseevent) {Dbgetresponseevent dbget= (dbgetresponseevent) event;}else if (event in
(file.length) After getting a long byte number, 1mb=1024kb,1kb=1024b, it is best to use this notation:BigDecimal megabyte = new BigDecimal (1024 * 1024);Float returnvalue = Filesize.divide (megabyte, 2, bigdecimal.round_up). Floatvalue ();More accurate accuracy !about how to make a jar package and run it in a timed way:Due to the use of three additional jar packages, all packaging methods are as follows:The first step:Step Two:The third step: Choose your own project, storage path, choose to joi
An action event occurs when the mouse clicks and releases;Method Summary:actionPerformed(ActionEvente)Called when an action occurs.Column:public class Shijian extends Frame{public static void Main (string[] args){Frame f = new frame ();F.setlayout (New FlowLayout (flowlayout.left,20,5));Button B1 = New button ("Stand-alone");Button B2 = New button ("Double-click");Button B3 = New button ("A3");Creating listenersMyactionlistener m = new Myactionlistener ();B1.addactionlistener (m);//Register the
Test thread deadlock, run the following code:
public class Test1 {
private static Object O1 = new Object ();
private static Object O2 = new Object ();
public static void Main (string[] args) {for
(int i = 0;ipublic void Run () {
synchronized (O1) {
synchronized (O2) {
System.out.println ("AM O1");
}
}
}). Start ();
New Thread (New Runnable () {
@Override public
void Run () {
synchronized (O2) {
synchronized (O1) { C19/>system.out.print
Linux lower port and service is corresponding, the Java process starts by default listening on 8080 port, if the service is hung up, 8080 port is not.The lsof-i:8080 port, if there is no output, indicates that the port is not working.Want to monitor the Java process 8080 port on the Zabbix platform, if the port hangs up can send an email or send a text message!Implementation method:1. Create a template firs
The JDK itself has a lot of monitoring tools, such as Jconsole.The tool we are going to talk about today is VISUALVM, which is one of them. But this tool is only in JDK1.6.07 and above. It is a good free monitoring tool to monitor the JVM heap, thread, class loading situation and JVM GC condition of Java programs.Monitoring range: JDK1.4 and above versions of the
"; System. out. println (count); S= S+count; if(Count = =1) {System. out. println ("1 start sleeping for 5 seconds"); Thread.Sleep ( the); System. out. println ("1 after sleeping,"); } System. out. println (count+"End of execution"); returns; } }}As the test code shows, the thread is not finished and will pass through the System. Out.println (f.get()); Blocking, this method does not end, and it can be used to monitor the execution time of the thread.If you remove System. This method ends
The path class of nio.2 provides a way to listen for changes to the file system.Register (watcherservice Watcher,watchevent.kindWatchservice has three methods to listen for file change events in the directory.Watchkey poll (): Gets the next Watchkey and returns null immediately if no watchkey occurs;Watchekey Poll (Long timeout,timeunit unit): Try to wait for timeout time to get the next watchkey;Watchkey take (): Gets the next Watchkey and waits if it doesn't happen;If the program needs to be m
Java Web concurrency: for update practices, monitoring and solving ., Javawebupdate
Writer: BYSocket)
Weibo: BYSocket
Douban: BYSocket
I. Preface
We have been talking about concurrency. At present, there are two common practices: Lock Mechanism: 1. pessimistic lock; 2. Optimistic lock.
However, this article is mainly used to record my processing experience. In addition, I hope to see the great gods, Daniel,
());7Frame.setvisible (true);8 }9 }Ten classMywindowlistenerImplementsWindowListener One { A @Override - Public voidwindowopened (windowevent e) { - } the //Click on the fork on the top of the window to call - @Override - Public voidwindowclosing (windowevent e) { -SYSTEM.OUT.PRINTLN ("World"); + //method of program exit -System.exit (0); + } A //when calling the Dispose method at @Override - Public voidwindowclosed (windowevent e) - { -System.out.
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.