java socket参数详解:BackLog
- - 开源软件 - ITeye博客 java socket参数详解:BackLog. 输入连接指示(对连接的请求)的最大队列长度被设置为 backlog 参数. 如果队列满时收到连接指示,则拒绝该连接. backlog参数必须是大于 0 的正值. 如果传递的值等于或小于 0,则假定为默认值. 经过测试这个队列是按照 FIFO(先进先出)的原则.
public static void testBase(int i) { i = 2; }
int i = 10; System.out.println(i);//10 testBase(i); System.out.println(i); //10
public static void testObj(Object o) { o = new Object(); }
Object o = new Object(); System.out.println(o);// java.lang.Object@1ff61bcf testObj(o); System.out.println(o);//java.lang.Object@1ff61bcf
public class S { private Object o = new Object(); private int i = 2; public Object getO() { return o; } public void setO(Object o) { this.o = o; } public int getI() { return i; } public void setI(int i) { this.i = i; } }测试方法:
public static void testA(S s) { s.setI(100); s.setO(new Object()); }
S s = new S(); System.out.println(s.getI()+","+s.getO());// 2,java.lang.Object@11b75be2 testA(s); System.out.println(s.getI()+","+s.getO());//100,java.lang.Object@1cf15b84
package test; public class A { int t = 6; Object obj = new Object(); public static void main(String[] args) { A a = new A(); a.func(a.t,a.obj);//问t和obj的值是否变化,答案:不变化 } public void func(int t,Object obj) { t = 7; obj = null; } }
public static void testArr(int[] arr) { arr = null; }测试:
int[] arr = {1,2}; System.out.println(arr[0]);//1 testArr(arr); System.out.println(arr[0]); //1
public static void testArr(int[] arr) { arr[0] = 100; }测试:
int[] arr = {1,2}; System.out.println(arr[0]);//1 testArr(arr); System.out.println(arr[0]);//100
public static void testWrapper(Float f) { f = 100.0f; }测试:
Float f = 12.0f; System.out.println(f);//12.0 testWrapper(f); System.out.println(f);//12.0
public static void testStr1(String str) { str = "testOK"; }测试:
String str = "test"; System.out.println(str);//test testStr1(str); System.out.println(str);//test根据前面的思路,字符串也是对象,参数拷贝的是对象的地址,在方法内部将参数指向另一个堆对象并不影响原始对象引用的指向。
public static void testStr2(String str) { str = str.concat("OK"); str = str.toUpperCase(); }测试:
String str = "test"; System.out.println(str);//test testStr2(str); System.out.println(str);//test
public static void testStr3(String str) { str += "OK"; }测试:
String str = "test"; System.out.println(str);//test testStr3(str); System.out.println(str);//test如果你以为第二次输出testOK,那就错啦,String类的’+‘是经过重载的,编译时会还原成StringBuilder的append操作,并且new了一个StringBuilder对象:
str += "OK"; str = new StringBuilder(str).append("OK").toString();//编译时会还原成这样
public static void testStringBuilder(StringBuilder sb) { sb = new StringBuilder("testOK"); }测试:
StringBuilder sb = new StringBuilder("test"); System.out.println(sb.toString());//test testStringBuilder(sb); System.out.println(sb.toString());//test6.2在方法内部调用StringBuffer或StringBuilder的append方法:
public static void testStringBuilder(StringBuilder sb) { sb.append("OK"); }测试:
StringBuilder sb = new StringBuilder("test"); System.out.println(sb.toString());//test testStringBuilder(sb); System.out.println(sb.toString());//testOK
public static void swap(Integer a, Integer b) { Integer temp = a; a = b; b = temp; }这根本不能交换两个数.