[JAVA tool] jstack is simple to use to locate problems such as endless loops, thread blocking, and deadlocks. javajstack
When we run a java program and find that the program is not moving, but we don't know where the problem is, we can use the jstack tool that comes with JDK to locate it;
Let's just look at the example on the window platform;Endless loop
The Prog
In Java, to jump out of multiple loops, you can define a label in front of the outer loop statement, and then use a labeled break statement in the code of the inner loop body to jump out of the outer loop. For exampleOk:for (int i=0;ifor (int j=0;jSystem.out.println ("i=" + i + ", j=" + j); if (j = = 5) break OK;}}In addition, it is not recommended to use labels this way, but to let the result of the outer
In Java, to jump out of multiple loops, you can define a label in front of the outer loop statement, and then use a labeled break statement in the code of the inner loop body to jump out of the outer loop. For example:OK: for(intI=0;iTen; i++) { for(intj=0;jTen; j + +) {System. out. println ("i=" + i + ", j=" +j); if(J = =5) BreakOK; } } for(intI=0;i4; i++){ for(intj=0;j5; j +
Break in Java can only jump out of the current loop, and to jump out of multiple loops you can label the label:Cases: PublicclassStepovermultiloop { Public StaticvoidMain (string[] args) {intcount = 0; OK: for(int i = 0; i for(intj = 0; J if((i + j) = = Ten) {System. out. println (++count); BreakOK;}}}}}How to jump out of multiple loops in
In Java, to jump out of multiple loops, you can define a label in front of the outer loop statement, and then use a labeled break statement in the code of the inner loop body to jump out of the outer loop. For exampleOk:for (int i=0;i{for (int j=0;j{System.out.println ("i=" + i + ", j=" + j);if (j = = 5) break OK;}}In addition, I personally do not usually use the label this way, but let the outer loop condi
Using flag bits to control loopsThe usual techniques for controlling loops are mentioned earlier: counter-controlled loops. Another common technique for controlling loops is to assign a special value when reading and processing the value of a collection. This particular input value also becomes the flag value (Sentinel values), Used to indicate the end of the loo
1.1. Enhanced for loop enhanced for loops can simplify the traversal of arrays and collections at some point. The enhanced for Loop requires a collection to implement the iterable interface. Public Static voidMain (string[] args) {//iterating through an array for(String S:args) {System.out.println (s);} ArrayListNewArraylist(); Arraylist.add (1); Arraylist.add (3); Arraylist.add (5); //The usual way to traverse the collectionIteratorarraylist.iterat
In java, how does one jump out of the current multiple loops?
Use break directly. For example:
Package com. test; public class test {public static void main (String [] args) {for (int I = 0; I Output result: I = 1 j = 0
I = 2 j = 0
I = 2 j = 1
I = 3 j = 0
I = 3 j = 1
I = 3 j = 2
I = 4 j = 0
I = 4 j = 1
I = 4 j = 2
I = 4 j = 3
Now, make a slight modification to the Code to jump out
collection. The effect is not different, the performance gap is huge. importjava.util.*;p ublicclasstest1{publicstaticvoid main (String[]args) { List Post three run results: 1.use. size-->4907262do size-->41760792.use. Size-->7835279do not use. Size-->63330893.use. size-- >8000729do not use. size-->6663169 Do not wait until the performance bottleneck to optimize the code, but in the development of the appropriate consideration, compared to the performance bottlenecks to refactor these small det
:getstatic# 2/ /fieldjava/lang/system.out:ljava/io/printstream;11 : iload_112: invokevirtual #3// methodjava/io/printstream.println: (I) v15: iinc1,1 18:goto2 21:return Now analyze how the for loop is executed. First Initialize the loop variable first: 0:iconst_0 1:istore_1 These two lines of code are equivalent to the code int i = 0 (Iconst_0 is the number 0,istore_1 is the local variable 1, here is the source of i) then judge the loop condition: 2:iload_1 3:bipush 5:if_icmpge 21 These three
/** How do I jump out of the current multiple nested loops in Java?* In Java, to jump out of multiple loops, you can define a label in front of the outer loop statement,* Then use the break statement with a label in the code of the inner loop body to jump out of the outer loop*/Package
}Ten}2. Print as shape (positive triangle)1 Public classfordemo2{2 Public Static voidMain (string[] args) {3 for(inti=0;i){4 for(intj=0;j){5System.out.print ("*");6 }7 System.out.println ();8 }9 }Ten}(1) through the loop nested printing similar to this diagram, the outer loop control the number of rows, the inner loop control the number of columns, that is, the number of each row.(2) for the graph of decreasing (inverted triangles)
The For Each loop is also the first to see, "Java SE 5.0 adds a powerful looping structure that can be used to work with each element in the array at once (or a collection of other types of elements) without being distracted by specifying subscript values."The statement format for this enhanced for Each loop is:for (variable:collection) statementDefines a variable that is used to stage each element of a collection and executes the corresponding statem
Everyone is good, I believe everyone is directed at the name of it, in fact, this is just my personal self-study some experience, not much advanced knowledge points, only applicable to some beginners to learn Java casually. Well, the nonsense is not much to say, the following for a moment, today I learned the new knowledge points.Actually to say today I learned how much, actually not many, knew the Java Som
Package Test.testdemo;import Org.springframework.jdbc.core.jdbctemplate;import Com.util.pub;public class Test4 { public static void Main (string[] args) {String-sql = "INSERT into temp_spring (AAC003, AAC002, D, E, F, G, H, I, J, K)" + "Values (' Tom ', ' 51253319700126xxxx ', ' Dayi County Jin North Road No. 1151th ', ' Chengdu ', ' 5 ', ' 5 ', ' 4 ', ' Dayi County People's Hospital ', ' Dayi hospital ', ' Dayi County second People's Hospital ');//used to receive re The SQL statement after plac
For-each Cycle// first cycle, k=data[0]; // second cycle, k=data[1]; // ... for (int//data is an array { xxxxx;}Copy of arrayintA//A is the ownerint[]a=New int[100];//A is the managerint[]b=a;//B is manager A and B co-manage an array (change the value of B (a) [x] To change the value of a (b) [x])so the method of copying array A to array B is as follows:int[]a=New int[xx];int[]b=New int[a.length]; for(i=0;i) B[i]=a[i];Java Learning Notes (For-eac
divisible by 3 int sum = 0; for (int i = 0; I ) { if(i%3==0) { + = i; } } SYSTEM.OUT.PRINTLN (sum);Strengthen for loop (foreach) for (E e:eary) { dosomething (); }The strengthen for loop consists of declaring statements and accessing the array two parts, declaring statements used to declare local variables, and the type must be the same as the array name used to iterate through each element in the array.// prints information about all the elements in the list for (St
package regular expression; public class Rudolph {public static void main (string[] args) {//TODO auto-generated method stubstring[] Str = new string[]{"Rudolph", "[Rr]udolph", "[rr][aeiou][a-z]ol.*", "r.*"};for (String pattern:str) System.out.println (" Rudolph ". Matches (pattern)); for (String ss:str)//The data in the container str is traversed by one of the data of type String. SYSTEM.OUT.PRINTLN (ss); for (int i =0;iOutput Result:Use an example of a regular expression to illustrate two for
One. Last talk about if and if---else branch structure, this time if---else if, and switch---case
if (Boolean) {
Statement}else if (Boolean) {Statement}else{Statement}2. Switch (Boolean) {///Advantage structure is clear, high efficiency, the disadvantage can only judge the case of equal numbers.Case 1:StatementCase 2:Statement。。。。。。Default:Statement}Two. CycleThree elements of the loop:1. Loop variable Initialization2. Cyclic conditions (based on cyclic variables)3. Change of the c
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.