Month: July 2014

Java多线程

http://stackoverflow.com/questions/10684111/can-notify-wake-up-the-same-thread-multiple-times

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html

Difference between Binary Semaphore and Mutex

http://stackoverflow.com/questions/62814/difference-between-binary-semaphore-and-mutex

Java并发之读写锁Lock和条件阻塞Condition的应用(转载)

http://www.cnblogs.com/yaowukonga/archive/2012/08/27/2658329.html

 

H2O与Java线程同步

http://www.cnblogs.com/lautsie/p/3430356.html

http://ttianzhao.blogspot.com/2014/07/concurrent-h2o.html

 

A Java example of bounded buffer

http://www.cnblogs.com/yaowukonga/archive/2012/08/27/2658329.html

public class BoundedBuffer{

final Lock lock = new ReentrantLock();

final Condition notFull = lock.newCondition();

final Condition notEmpty = lock.newCondition();

 

final Object [] items = new Object[100];

int putptr, takeptr, count;

public void put(Object x) throws InterruptedException{

lock.lock();

try{

while(count == items.length)  notFull.await();

items[putptr] = x ;

if( ++putptr == items.length)  putptr=  0 ;

++count;

notEmpty.signal();

} finally{

lock.unlock();

}

}

public Object take() throws InterruptedException{

lock.lock();

try{

while ( count == 0 )   notEmpty.await();

Object x = items[takeptr];

if( ++takeptr == items.length)  takeptr=  0;

— count ;

notFull.signal();

return x ;

}finally{

lock.unlock();

}

}

}

http://tutorials.jenkov.com/java-concurrency/blocking-queues.html

public class BlockingQueue{
private List queue = new LinkedList();
private int limit = 10 ;
public BlockingQueue(int limit){
this.limit = limit ;
}

public synchronized void enqueue(Object item) throws InterruptedException{
while(this.queue.size() == this.limit){
wait();
}
if(this.queue.size() == 0){
notifyAll();
}
this.queue.add(item) ;
}

public synchronized void deque() throws InterruptedException {
while(this.queue.size() == 0 ) {
wait;
}
if( this.queue.size() == this.limit) {
notifyAll();
}
return this.queue.remove(0);

}

}

 

google linkedin facebook面经集锦

Google:

http://www.yiyome.com/article/view/1003229-google-.html

Given API:
int Read4096(char* buf);
It reads data from a file and records the position so that the next time when it is called it read the next 4k chars (or the rest of the file, whichever is smaller) from the file.
The return is the number of chars read.

Todo: Use above API to Implement API
“int Read(char* buf, int n)” which reads any number of chars from the file.

http://www.careercup.com/question?id=14424684

 

*****************************************************************

Linkedin:

http://www.amoduo.com/article/view/1003269-linkedin-.html

http://www.mitbbs.com/article_t/JobHunting/32331973.html

http://www.weiming.info/zhuti/JobHunting/31909473/

http://blog.sina.com.cn/s/blog_696e177d0101c4vv.html

**************************************************************

 

f design question 总结

http://blog.csdn.net/sigh1988/article/details/9790337

http://www.mitbbs.com/article_t/JobHunting/32741713.html