注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
发一个vmware的面经
Phone interview:
直接贴代码吧- //Implement a thread pool
- //
- //Fixed number of thread 64
- //
- //void Inpool (thread *) -- return a thread back to thread pool
- //Thread * Outpool (Task *) -- dispatch a thread to task, always dispatch longest waiting thread
- public class ThreadPoll {
- Thread[] arr;
- private int head;
- private int count;
- public ThreadPoll() {
- arr = new Thread[64];
- head = 0;
- for (int i = 0; i < 64; i++) {
- arr[i] = new Thread();
- }
- count = 64;
- }
- synchronized void Inpool(Thread thread) {
- int pos = (head + count) % 64;
- count++;
- arr[pos] = thread;
- if (count == 1) {
- notifyAll();
- }
- }
- synchronized Thread Outpool(Task task) {
- while (count == 0) {
- try {
- wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- count--;
- int pos = head;
- head = (++head) % 64;
- return arr[pos];
- }
- class Task {
- }
- }
复制代码 Onsite:
1. 这个真的讲不清楚,如遇到做一个Project,做了一半不让做了怎么办等
看了面经,请加分噢~
|