- 浏览: 465967 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
ty1972873004:
sunwang810812 写道我运行了这个例子,怎么结果是这 ...
Java并发编程: 使用Semaphore限制资源并发访问的线程数 -
lgh1992314:
simpleDean 写道请问,Logger.setLevel ...
Java内置Logger详解 -
sunwang810812:
我运行了这个例子,怎么结果是这样的:2号车泊车6号车泊车5号车 ...
Java并发编程: 使用Semaphore限制资源并发访问的线程数 -
jp260715007:
nanjiwubing123 写道参考你的用法,用如下方式实现 ...
面试题--三个线程循环打印ABC10次的几种解决方法 -
cb_0312:
SurnameDictionary文章我没看完,现在懂了
中文排序
本文记录三道多线程编程题。
第一道:
有四个线程1、2、3、4。线程1的功能就是输出A,线程2的功能就是输出B,以此类推......... 现在有四个文件file1,file2,file3, file4。初始都为空。
现要让四个文件呈如下格式:
file1:A B C D A B....
file2:B C D A B C....
file3:C D A B C D....
file4:D A B C D A....
程序如下:
程序运行结果:
控制台输出--->
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
file1文件中的内容-->
ABCDABCDABCDABCD
file2文件中的内容:-->
BCDABCDABCDABCDA
file3文件中的内容:-->
CDABCDABCDABCDAB
file4文件中的内容:-->
DABCDABCDABCDABC
第二道:
一个线程打印 1~52,另一个线程打印字母A-Z。打印顺序为12A34B56C……5152Z。
http://mouselearnjava.iteye.com/blog/1949693
第三道
有三个线程分别打印A、B、C,请用多线程编程实现,在屏幕上循环打印10次ABCABC…
http://mouselearnjava.iteye.com/blog/1949228
谢谢你的指正,确实跑题了。
程序已经修正。
一个运行结果如下:
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
是的。JDK 1.5 之后的J.U.C 包对多线程编程是个很不撮的选择,方便很多。
第一道:
有四个线程1、2、3、4。线程1的功能就是输出A,线程2的功能就是输出B,以此类推......... 现在有四个文件file1,file2,file3, file4。初始都为空。
现要让四个文件呈如下格式:
file1:A B C D A B....
file2:B C D A B C....
file3:C D A B C D....
file4:D A B C D A....
程序如下:
package my.test; import java.io.FileWriter; import java.io.IOException; public class FileWriteUtil { private int currentThreadNum = 1; /** 记录将字符写入文件的次数 */ private int count = 0; private int currentFileNum = 1; public void write(char value, int threadNum) { generateNextFileNum(); FileWriter writer = null; try { writer = new FileWriter("file" + currentFileNum + ".txt", true); writer.write(String.valueOf(value)); System.out.printf( "ThreadNum=%d is executing. %c is written into file file%d.txt \n", currentThreadNum, value, currentFileNum); writer.flush(); count++; currentThreadNum = threadNum; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (null != writer) { try { writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { writer = null; } } generateNextThreadNum(); } public int getCurrentThreadNum() { return currentThreadNum; } public void setCurrentThreadNum(int currentThreadNum) { this.currentThreadNum = currentThreadNum; } private void generateNextFileNum() { if (count % 4 == 0) { currentFileNum = 1; }else { currentFileNum++; } } private void generateNextThreadNum() { if (count % 4 == 0) { if (currentThreadNum < 3) { currentThreadNum += 2; } else { currentThreadNum = (currentThreadNum + 2) % 4; } }else { if(currentThreadNum == 4) { currentThreadNum=1; }else { currentThreadNum++; } } } }
package my.test; public class WriteRunnable implements Runnable { private FileWriteUtil util = null; private int threadNum = 1; private char value = ' '; /** * @param util */ public WriteRunnable(FileWriteUtil util, int threadNum, char value) { super(); this.util = util; this.threadNum = threadNum; this.value = value; } public void run() { /** * 假设循环16次, 一直循环可以使用while(true) 或者 for(;;) */ for (int i = 0; i < 16; i++) { synchronized (util) { while (threadNum != util.getCurrentThreadNum()) { try { util.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } util.write(value, threadNum); util.notifyAll(); } } } }
package my.test; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * 有四个线程1、2、3、4。 * * 线程1的功能就是输出A,线程2的功能就是输出B, * * 以此类推......... 现在有四个文件file1, * file2,file3, file4。初始都为空。现要让四个文件呈如下格式: * file1:A B C D A B.... * file2:B C D A B C.... * file3:C D A B C D.... * file4:D A B C D A.... * * @author Eric * */ public class Main { public static void main(String[] args) { FileWriteUtil util = new FileWriteUtil(); ExecutorService service = Executors.newCachedThreadPool(); service.execute(new WriteRunnable(util, 1, 'A')); service.execute(new WriteRunnable(util, 2, 'B')); service.execute(new WriteRunnable(util, 3, 'C')); service.execute(new WriteRunnable(util, 4, 'D')); service.shutdown(); } }
程序运行结果:
控制台输出--->
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
file1文件中的内容-->
ABCDABCDABCDABCD
file2文件中的内容:-->
BCDABCDABCDABCDA
file3文件中的内容:-->
CDABCDABCDABCDAB
file4文件中的内容:-->
DABCDABCDABCDABC
第二道:
一个线程打印 1~52,另一个线程打印字母A-Z。打印顺序为12A34B56C……5152Z。
http://mouselearnjava.iteye.com/blog/1949693
第三道
有三个线程分别打印A、B、C,请用多线程编程实现,在屏幕上循环打印10次ABCABC…
http://mouselearnjava.iteye.com/blog/1949228
评论
4 楼
MouseLearnJava
2013-10-16
dujiayi001 写道
弱弱的问一句,我跑了你的代码,但是出来结果是:
pool-1-thread-1 : A.txt=>A
pool-1-thread-2 : B.txt=>B
pool-1-thread-3 : C.txt=>C
pool-1-thread-4 : D.txt=>D
pool-1-thread-1 : A.txt=>B
pool-1-thread-2 : B.txt=>C
pool-1-thread-3 : C.txt=>D
pool-1-thread-4 : D.txt=>A
pool-1-thread-1 : A.txt=>C
pool-1-thread-2 : B.txt=>D
pool-1-thread-3 : C.txt=>A
pool-1-thread-4 : D.txt=>B
跟题目问的好像不对劲,题目要求是线程1的功能就是输出A,线程2的功能就是输出B,而你的结果是线程1只输出A文件
pool-1-thread-1 : A.txt=>A
pool-1-thread-2 : B.txt=>B
pool-1-thread-3 : C.txt=>C
pool-1-thread-4 : D.txt=>D
pool-1-thread-1 : A.txt=>B
pool-1-thread-2 : B.txt=>C
pool-1-thread-3 : C.txt=>D
pool-1-thread-4 : D.txt=>A
pool-1-thread-1 : A.txt=>C
pool-1-thread-2 : B.txt=>D
pool-1-thread-3 : C.txt=>A
pool-1-thread-4 : D.txt=>B
跟题目问的好像不对劲,题目要求是线程1的功能就是输出A,线程2的功能就是输出B,而你的结果是线程1只输出A文件
谢谢你的指正,确实跑题了。
程序已经修正。
一个运行结果如下:
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
ThreadNum=1 is executing. A is written into file file1.txt
ThreadNum=2 is executing. B is written into file file2.txt
ThreadNum=3 is executing. C is written into file file3.txt
ThreadNum=4 is executing. D is written into file file4.txt
ThreadNum=2 is executing. B is written into file file1.txt
ThreadNum=3 is executing. C is written into file file2.txt
ThreadNum=4 is executing. D is written into file file3.txt
ThreadNum=1 is executing. A is written into file file4.txt
ThreadNum=3 is executing. C is written into file file1.txt
ThreadNum=4 is executing. D is written into file file2.txt
ThreadNum=1 is executing. A is written into file file3.txt
ThreadNum=2 is executing. B is written into file file4.txt
ThreadNum=4 is executing. D is written into file file1.txt
ThreadNum=1 is executing. A is written into file file2.txt
ThreadNum=2 is executing. B is written into file file3.txt
ThreadNum=3 is executing. C is written into file file4.txt
3 楼
dujiayi001
2013-10-15
弱弱的问一句,我跑了你的代码,但是出来结果是:
pool-1-thread-1 : A.txt=>A
pool-1-thread-2 : B.txt=>B
pool-1-thread-3 : C.txt=>C
pool-1-thread-4 : D.txt=>D
pool-1-thread-1 : A.txt=>B
pool-1-thread-2 : B.txt=>C
pool-1-thread-3 : C.txt=>D
pool-1-thread-4 : D.txt=>A
pool-1-thread-1 : A.txt=>C
pool-1-thread-2 : B.txt=>D
pool-1-thread-3 : C.txt=>A
pool-1-thread-4 : D.txt=>B
跟题目问的好像不对劲,题目要求是线程1的功能就是输出A,线程2的功能就是输出B,而你的结果是线程1只输出A文件
pool-1-thread-1 : A.txt=>A
pool-1-thread-2 : B.txt=>B
pool-1-thread-3 : C.txt=>C
pool-1-thread-4 : D.txt=>D
pool-1-thread-1 : A.txt=>B
pool-1-thread-2 : B.txt=>C
pool-1-thread-3 : C.txt=>D
pool-1-thread-4 : D.txt=>A
pool-1-thread-1 : A.txt=>C
pool-1-thread-2 : B.txt=>D
pool-1-thread-3 : C.txt=>A
pool-1-thread-4 : D.txt=>B
跟题目问的好像不对劲,题目要求是线程1的功能就是输出A,线程2的功能就是输出B,而你的结果是线程1只输出A文件
2 楼
MouseLearnJava
2013-10-14
cywhoyi 写道
挺好练习,第一题我采用的是
信号量+原子类的操作,感觉比LZ更为简洁,顶下面试而用
private static Semaphore A = new Semaphore(1); private static Semaphore B = new Semaphore(1); private static Semaphore C = new Semaphore(1); private static Semaphore D = new Semaphore(1); private static AtomicInteger value = new AtomicInteger(1);
信号量+原子类的操作,感觉比LZ更为简洁,顶下面试而用
是的。JDK 1.5 之后的J.U.C 包对多线程编程是个很不撮的选择,方便很多。
1 楼
cywhoyi
2013-10-14
挺好练习,第一题我采用的是
信号量+原子类的操作,感觉比LZ更为简洁,顶下面试而用
private static Semaphore A = new Semaphore(1); private static Semaphore B = new Semaphore(1); private static Semaphore C = new Semaphore(1); private static Semaphore D = new Semaphore(1); private static AtomicInteger value = new AtomicInteger(1);
信号量+原子类的操作,感觉比LZ更为简洁,顶下面试而用
发表评论
-
工厂类中移除if/else语句
2016-07-10 19:52 900面向对象语言的一个强大的特性是多态,它可以用来在代码中移除 ... -
Java编程练手100题
2014-12-11 17:13 6728本文给出100道Java编程练手的程序。 列表如下: 面 ... -
数组复制的三种方法
2014-11-30 12:57 2212本文将给出三种实现数组复制的方法 (以复制整数数组为例)。 ... -
数组复制的三种方法
2014-11-30 12:54 0本文将给出三种实现数组复制的方法 (以复制整数数组为例)。 ... -
四种复制文件的方法
2014-11-29 13:21 1739尽管Java提供了一个类ava.io.File用于文件的操 ... -
判断一个字符串中的字符是否都只出现一次
2014-11-25 12:58 2724本篇博文将给大家带来几个判断一个字符串中的字符是否都只出现一 ... -
使用正则表达式判断一个数是否为素数
2014-11-23 13:35 2166正则表达式能够用于判断一个数是否为素数,这个以前完全没有想过 ... -
几个可以用英文单词表达的正则表达式
2014-11-21 13:12 3748本文,我们将来看一下几个可以用英文单词表达的正则表达式。这些 ... -
(广度优先搜索)打印所有可能的括号组合
2014-11-20 11:58 1953问题:给定一个正整n,作为括号的对数,输出所有括号可能 ... -
随机产生由特殊字符,大小写字母以及数字组成的字符串,且每种字符都至少出现一次
2014-11-19 14:48 3976题目:随机产生字符串,字符串中的字符只能由特殊字符 (! ... -
找出1到n缺失的一个数
2014-11-18 12:57 3173题目:Problem description: You h ... -
EnumSet的几个例子
2014-11-14 16:24 8749EnumSet 是一个与枚举类型一起使用的专用 Set 实现 ... -
给定两个有序数组和一个指定的sum值,从两个数组中各找一个数使得这两个数的和与指定的sum值相差最小
2014-11-12 11:24 3327题目:给定两个有序数组和一个指定的sum值,从两个数组 ... -
Java面试编程题练手
2014-11-04 22:49 6700面试编程 写一个程序,去除有序数组中的重复数字 编 ... -
Collections用法整理
2014-10-22 20:55 9846Collections (java.util.Collect ... -
The Code Sample 代码实例 个人博客开通
2014-09-04 18:48 1417个人博客小站开通 http://thecodesample. ... -
Collections.emptyXXX方法
2014-06-08 13:37 2145从JDK 1.5开始, Collections集合工具类中预先 ... -
这代码怎么就打印出"hello world"了呢?
2014-06-08 00:37 7396for (long l = 4946144450195624L ... -
最短时间过桥
2014-04-21 22:03 4137本文用代码实现最短时间过桥,并且打印如下两个例子的最小过桥时间 ... -
将数组分割成差值最小的子集
2014-04-20 22:34 2899本文使用位掩码实现一个功能 ==》将数组分割成差值最小的子集 ...
相关推荐
多线程并发编程是Java编程中重要的一块内容,也是面试重点覆盖区域。所以,学好多线程并发编程对Java程序员来来说极其重要的。
该PMP模拟练习题共有180道题,包括170道单选题和10道多选题,旨在评估项目管理专业人的知识和技能。该练习题涵盖了项目管理知识领域的多个方面,包括项目启动、计划、执行、监控和控制、关闭等阶段。 从试题中可以...
施工高处作业安全技术规范方案(jgj80~2016年)考试题(卷)库单选50道多选20道判断30道.doc
6. **商业银行经营方针**:在商业银行的经营方针中,“**安全性**”、“**流动性**”和“**盈利性**”被认为是三个基本原则。其中,安全性是基础,流动性是条件,而盈利性是目标。 7. **基础货币的影响因素**:在...
最后的2道编程题,可能是设计并实现一个小型的功能模块或者解决一个实际问题。这类题目旨在检验复习者的实际编程能力和问题解决能力,这在实际工作中尤为重要。 总结来说,这份复习资料全面覆盖了Java编程的各个...
第三题涉及到函数的奇偶性及图像识别,通过排除法确定函数的图形。这需要考生理解函数的基本性质和图像特征。 4. 定义域的求解 第四题要求确定函数的定义域,这需要考生解决不等式组来找到函数能够取值的区间。 ...
例如,描述中提到的两道多选题,第一题是单选题,只有一项正确答案;第二题是多选题,要求选择两个正确选项。 在设计多选题时,IT专家通常会遵循以下原则: 1. **难度适中**:确保题目的难度适合目标群体,避免过于...
精心制作:其中包含九十道单选题、二十道多选题、九十道填空题、十道简答题。包含各种难点、易错点
5. **制约课程改革的因素**:第五题中提到的三大因素——社会、知识、儿童,是影响课程改革的重要条件,课程设计需考虑社会需求、学科知识的更新以及学生的成长需求。 6. **教师的观察力**:第七题提到的教师具备的...
12. 管理授权:第十三道单选题描述了一种授权方式——柔性授权,允许下属在一定范围内自主决策。 13. 心理学:第十四道判断题指出团体凝聚力与从众行为的关系,凝聚力强的团队更易出现从众行为。 14. 法律权利:第...
13. **三次产业划分**:第十三道单选题关于产业分类,划分三次产业的依据主要是生产要素的密集程度。 14. **经济体制改革**:第十四道单选题提到党的十八大强调健全现代市场体系。 15. **不告不理原则**:第十五...
复赛则转为编程题,包含4道操作题和2道附加题,满分150分,考试时间为3小时,侧重考察Java语言的实际操作能力。决赛依然为编程题,但难度升级,两道题目分别检验选手解决问题和创新思维的能力,满分为120分,考试...
可以实现单选题、多选题维护、填空题、判断题的在线维护和管理,添加生成试卷后可以自动从题库进行调用试题,考试完成后自动打分,后台可以进行统计。 考试科目 考试科目添加 考试科目维护 用户信息 用户添加 用户...
描述中提到的38道单选题和19道多选题,这些练习题通常用于检验学习者对Java知识的理解和掌握程度。单选题可能涉及到基本语法、数据类型、运算符、流程控制语句等基础知识;而多选题则可能更倾向于考察更复杂的概念,...
13. **复数的实部与代数运算**:填空题第十三题要求解复数的实部,这需要通过复数的代数运算来实现。 14. **向量的线性组合与坐标运算**:填空题第十四题可能涉及到向量的线性组合,通过坐标运算求解。 15. **向量...
1. 《法律法规与综合能力》:初级考试有90道单选题(每题0.5分,共45分)、40道多选题(每题1分,共40分)和15道判断题(每题1分,共15分)。 2. 《个人理财》:初级考试结构与《法律法规与综合能力》相同。 3. ...
500道单选题+200道多选题