由买买提看人间百态

topics

全部话题 - 话题: notifyall
1 2 下页 末页 (共2页)
i**p
发帖数: 902
1
来自主题: Java版 - java ,wait ,notify notifyall
I have the same question as this.
--------------------------------------------
I am confused a bit about wait and notify/notifyall.
I know there is a lock for every java object. I know wait will release the
lock for other thread. How about notify/notifyall? Does notify/notifyall
realse the lock it is holding for other thread?
-------------------------------------------------
There are 2 different answers for it on this link
http://stackoverflow.com/questions/5999193/java-wait-notify-not
Could an... 阅读全帖
r*****l
发帖数: 2859
2
来自主题: Java版 - java ,wait ,notify notifyall
Since you have the code, you should be able to run it and know the answers
to your questions. Seems that you are testing others :)
A will wait until B finishes the loop.
B releases the lock after the sync block.
To answer your question 3, you need to understandthe thread states. When A calls
wait(), A is put in the WAITING state. It will wait until a notify() or
notifyAll(). When that happens, A is NOT put int the RUNNABLE state, but
BLOCKED state. A waits for the lock in the BLOCKED state. When... 阅读全帖
D**C
发帖数: 6754
3
来自主题: JobHunting版 - 请教L家生成H2O水分子的题。
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class H2O {
//using blocking queue, so it's easy to just have 2 h and 1 o at most,
//other threads will be blocked.
ArrayBlockingQueue hQueue = new ArrayBlockingQueue(2);
ArrayBlockingQueue oQueue = new ArrayBlockingQueue(1);
AtomicInteger hCount = new AtomicInteger();
AtomicInteger h2oCount= new AtomicInteger();
AtomicInteger hPrintCount= new AtomicInteger();
... 阅读全帖
a**********0
发帖数: 422
4
来自主题: JobHunting版 - java concurrence 例子
继续consumer和producer的例子
package jc;
import java.util.*;
//what about there are two things to be synchronized?
public class ProCon2nd {
// a class object to store the strings
static List myListOne = new ArrayList();
static List myListTwo = new ArrayList();
// this is the thing getting synchronized
// it is static as it is the same for all instances
static Object myLock = new Object();
public void produce(){
... 阅读全帖
y*****e
发帖数: 712
5
public class BQueue {
private Queue q = new LinkedList();
private int limit;
public BQueue(int limit) {
this.limit = limit;
}
public synchronized void put (T t) throws InterruptedException {
while (isFull()) {
wait();
}
boolean e = isEmpty();
q.add(t);
if (e)
notifyAll();
}
public synchronized T get () throws InterruptedException {
while (isEmpty()) {
wait();
}... 阅读全帖
A*******e
发帖数: 2419
6
假设空队列时,先有dequeue执行,发现队列为空,等待。
这时来一个enqueue,调用notifyAll()之后,插入新对象之前,dequeue已经唤醒,试
图去删除,这时队列仍然可能是空啊。
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);
}
publi... 阅读全帖
l*******g
发帖数: 82
7
来自主题: Java版 - 请教一个多线程的问题
public void run() {
while (!done) {
synchronized (lock) { <---你这里加锁,最好放在while外
while (index.get() % threads != id) <---你这里判断条件
try {
lock.wait(); <---你这里是做什么?你如果想要wait(),
你就要有一个地方notify()。一旦你进入这里,你下面的notifyAll是永远都到达不了
的,因为你这个事wait forever!
} catch (Exception e) {
}
System.out.println("The id" + id + ": " + queue[index.get()]
);
if (index.increme... 阅读全帖
c********r
发帖数: 286
8
Pthread 没有,有一个thread的
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.isEmpty()){
notifyAll();
}

this.queue.add(item);
}
public synchronized Object dequeue() throws InterruptedException {
while(this.queue.isEmpty... 阅读全帖
s******y
发帖数: 72
9
来自主题: JobHunting版 - LinkedIn 面经
这是我当时写的代码, 返回的线程没有顺序要求,只要每次保证有2个H线程和一个O线
程返回就行了。 然后面试官又问我每次都wake up所有当前等待的线程,然后这些线程
竞争,最后只有三个能过。 如果线程很多的话,比如1000个H线程,会怎么样, 我说
会多消耗CPU,因为大多数线程会被唤醒然后又sleep。 解决方法是可以每次只唤醒2个
H线程和1个O线程
class h20{
int numOfH, numOfO;
int mutexO, mutexH;
public void H(){
synchronized(this){
if(++numOfH >= 2 && numOfO >= 1) {
mutexO += 1;
mutexH += 2;
numOfH -= 2;
numOfO -= 1;
this.notifyAll();
}
while(mutexH <= 0) {
... 阅读全帖
e***s
发帖数: 799
10
来自主题: JobHunting版 - LinkedIn 面经
问个很弱的问题,blocking queue不是就已经thread-safe吗? 怎么实现thread-safe
blocking queue?
找到下面JAVA代码,好像很标准的样子.
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 syn... 阅读全帖
s******y
发帖数: 72
11
来自主题: JobHunting版 - LinkedIn 面经
这是我当时写的代码, 返回的线程没有顺序要求,只要每次保证有2个H线程和一个O线
程返回就行了。 然后面试官又问我每次都wake up所有当前等待的线程,然后这些线程
竞争,最后只有三个能过。 如果线程很多的话,比如1000个H线程,会怎么样, 我说
会多消耗CPU,因为大多数线程会被唤醒然后又sleep。 解决方法是可以每次只唤醒2个
H线程和1个O线程
class h20{
int numOfH, numOfO;
int mutexO, mutexH;
public void H(){
synchronized(this){
if(++numOfH >= 2 && numOfO >= 1) {
mutexO += 1;
mutexH += 2;
numOfH -= 2;
numOfO -= 1;
this.notifyAll();
}
while(mutexH <= 0) {
... 阅读全帖
e***s
发帖数: 799
12
来自主题: JobHunting版 - LinkedIn 面经
问个很弱的问题,blocking queue不是就已经thread-safe吗? 怎么实现thread-safe
blocking queue?
找到下面JAVA代码,好像很标准的样子.
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 syn... 阅读全帖
n*******s
发帖数: 482
13
来自主题: JobHunting版 - LinkedIn 面经
int counter[2]; // count[0] count of O; count[1] count of H
int toRunH ;
int toRunO ;
void H( ){
sync(counter){
if(counter[0]>=1 && count[1]==2){
toRunH = 2;toRunO = 1;
counter.notifyAll();

}
count[1]++;
do{
counter.wait()
}while(toRunH==0)
toRunH--;
}
}
void O( ){
sync(counter){
if(counter[0]==1 && count[1]>=2){
toRunH = 2;toRunO = 1;
counter.notifyAll();

}
co... 阅读全帖
n*******s
发帖数: 482
14
来自主题: JobHunting版 - LinkedIn 面经
int counter[2]; // count[0] count of O; count[1] count of H
int toRunH ;
int toRunO ;
void H( ){
sync(counter){
if(counter[0]>=1 && count[1]==2){
toRunH = 2;toRunO = 1;
counter.notifyAll();

}
count[1]++;
do{
counter.wait()
}while(toRunH==0)
toRunH--;
}
}
void O( ){
sync(counter){
if(counter[0]==1 && count[1]>=2){
toRunH = 2;toRunO = 1;
counter.notifyAll();

}
co... 阅读全帖
r****i
发帖数: 528
15
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
试着解第一题:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class DeepIteratorImpl implements Iterator {
//use a flat list to store all elements
private int currIndex;
private ArrayList flatC;
// Constructor
public DeepIteratorImpl (Collection> c) {
currIndex=-1;
flatC=new ArrayList();
getElement(c, flatC);
}

//get all the elements from the collection
private void getElement(C... 阅读全帖
n****e
发帖数: 678
16
来自主题: JobHunting版 - thread-safe blockingqueue
在网上和版上搜了半天,implement一个thread-safe blockingqueue. 大家看看有没有
问题:
import java.utils.LinkedList;
public class BlockingQueue {
private int capactiy;
private LinkedList elements;

public BlockingQueue(int capacity) {
if (capacity <=0 ) {
throw new exception();
}

this.capacity = capacity;
this.elements = new LinkedList ();
}

public synchronized void put(T t) {
while(elements.size() == capacity) {
w... 阅读全帖
c*******7
发帖数: 438
17
来自主题: JobHunting版 - 想问一下那道H2O的多线程题
题目是这样的:实现两个函数: H() and O(), 这两个函数会被多线程调用。如果满足
当前2个线程调用H(),和1个线程调用O(),让以上3个线程返回,产生一个水分子(可能
是HHO,HOH,OHH)。调用H()的当前线程不能大于2,调用O()的当前线程不能大于1。
我思前想后,写了一个,请大家帮忙看看。(排版有问题,tab改成下划线了。。。)
(发现前面写的好像不太对,又改了一次)
private Object mutex = new Object;
private Semaphore hSemaphore = new Semaphore(2);
private Semaphore oSemaphore = new Semaphore(1);
private int hCount;
private int oCount;
public void H() {
____hSemaphore.acquire();
____processH();
____
____synchronize(mutex) {
________hCount++;
________if(oCount == 1... 阅读全帖
a**********0
发帖数: 422
18
来自主题: JobHunting版 - java concurrence 例子
经典的consumer和producer的例子
package jc;
import java.util.*;
public class ProCon {
// a class object to store the strings
static List myListOne = new ArrayList();

public void produce(){
synchronized(myListOne){
myListOne.add("firstNameOne");
// notice all waiting threads to stop waiting
myListOne.notifyAll();
System.out.println("Adding finished and the current myListOne.
size(): " + myListOne.size());
... 阅读全帖
m*v
发帖数: 6
19
来自主题: JobHunting版 - 请教L家生成H2O水分子的题。
是不是和blockingqueue一个道理啊?
用一个data structure去coordinate两个threads?
public class H2O {
private int hCount;
private int oCount;
public H2O() {
hCount = 0;
oCount = 0;
}
public synchronized void addH() throws InterruptedException {
if(hCount == 2 && oCount == 1) {
System.out.println("add H, H2O");
hCount = 0;
oCount = 0;
notifyAll();
}
else {
while(hCount == 2) {
Syste... 阅读全帖
g****v
发帖数: 971
20
来自主题: JobHunting版 - thread safe blocking queue问题
发现这个还是挺常见的,这是网上的标准解法,希望可以对大家有帮助。
唯一的问题是为什么2个方法里面都用while来判断, 而不是用if?
---------------------------------------------
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 Object dequeue()
throws InterruptedException{
while(this.queue.size() == 0){
wait();
}
if(this.queue.size() == t... 阅读全帖
l****c
发帖数: 782
21
来自主题: JobHunting版 - L家coding question一问
就是按照时间顺序执行Task那道题,我收集了一些答案自己写了一下,
还请大牛多多多多的指点下,有没有问题。
多谢,多谢!
public class ProcessingQueueTest extends Thread {
//用个minHeap存Tasks
private Queue Tasks = new PriorityQueue<>(new Comparator(){
public int compare(Task a, Task b) {
if (a.time < b.time) return -1;
else if (a.time > b.time) return 1;
else return 0;
}
});
private boolean isRunning = true;
// 加Task进Heap
public void addTask(Task task) {
synchron... 阅读全帖
F****n
发帖数: 3271
22
来自主题: Java版 - The best HashMap Cache solution
To be frankly I am afraid that you got a wrong solution. The problem is the
code here:
Object value = // initialization;
theWrap.putValue(value);
There are no memory barrier between initialization and the writes that set
the value before your synchronized notifyAll(). Image a thread read the
value before notifyAll(). It may detect the value is non
-null, but it actually may be uninitialized.
Your solution is essentially a double check pattern that tries to use notify
to solve the problem, not to
A**u
发帖数: 2458
23
import java.util.*;
import java.util.concurrent.locks.*;
public class PC_unsyn
{
public static void main(String[] args)
{
IntBuffer b = new IntBuffer();
Producer p = new Producer(b);
Consumer c = new Consumer(b);
p.setName("Producer");
c.setName("Consumer");
p.start();
c.start();
}
}
class IntBuffer
{
private int index;
private int[] buffer = new int[8];
private Lock bufferLock = new ReentrantLock();
private Cond... 阅读全帖
j****g
发帖数: 597
24
来自主题: Programming版 - java synchronized 问题
今天看programer_interview看到一个producer-customer并行的问题,用java写的(第7
章section 7.12). Program is written as:
class producer extends Thread {
......
void run() {
while (true) {
try {
putInt();
}
catch (...){};
}
}
private synchronized void putInt() throws ... {
while (index == MAX_CAPACITY) {
wait()
}
buffer[index] = ...
index++;
notifyAll();
}
private synchronized int getInt() throws ... {
notifyAll(); // I ha
A**u
发帖数: 2458
25
【 以下文字转载自 Java 讨论区 】
发信人: Augu (奥古), 信区: Java
标 题: 求教一个Java问题 IllegalMonitorStateException
发信站: BBS 未名空间站 (Tue Dec 11 11:31:48 2012, 美东)
import java.util.*;
import java.util.concurrent.locks.*;
public class PC_unsyn
{
public static void main(String[] args)
{
IntBuffer b = new IntBuffer();
Producer p = new Producer(b);
Consumer c = new Consumer(b);
p.setName("Producer");
c.setName("Consumer");
p.start();
c.start();
}
}
class Int... 阅读全帖
x*****p
发帖数: 1707
26
来自主题: JobHunting版 - skype phone screen 经
1. Difference between notify and notifyAll
2. Difference between sync a static method and non-static method
3. Difference between join and yield
4. How to stop a thread?
5. Talking about concurrent package
6. What is ThreadLocal class?
T*******i
发帖数: 4992
27
来自主题: JobHunting版 - multi-threading guru们
java monitor
wait/notify/notifyAll
h******3
发帖数: 351
28
来自主题: JobHunting版 - multi-threading guru们
恕我弩钝, 请问这题和career cup 上的那个题目有啥区别啊?
class F{
public A(); public B(); public C();
}
Can you design a mechanism to make sure that B is executed after A, C is
executed after B?
And the solution is using two semaphore synchronize between A&B, B&C. I
think the question is talking about multithreads share the same objects.
在Java里就是用wait and notifyall.
谢谢
c******w
发帖数: 102
29
通过我的亲身体验,真的发现这个版的祝福真是有神奇的效果。十天前我在版上发了个
帖 《屡战屡败再次出征求祝福》, 记得有的朋友还回帖说应该叫屡败屡战,在此也谢
谢各位的bless。 也许就是因为有了这些祝福才有了我这次出征的神奇之旅。
此次受R公司邀请去onsite,需要在休斯敦转机。 从休斯敦到SF需要4个小时的飞行,
所以我决定利用这4个小时好好抱抱佛脚。 我先是老实的看了一个小时的关于TCP/IP的
一个chapter。然后开始练练一些可能被问到的算法题。 突然旁边的一个很PP的美国
Lady过来和我搭讪, 问我是不是computer engineer。我就告诉她说,我现在还不是,
但是这次是过来onsite interview一个公司的这个岗位。 于是PPMM就告诉我她是一个
IT公司T的HR director,而且他们公司现在正在招人,问问要不要给她寄个我的resume
。 一路上我们还闲聊了一会儿。 周一我在去R公司之前, 就把我的resume给PPMM发过
去了, 马上就收到回信说她会让engineer和我周二phone interview。在周二的phone
interv... 阅读全帖
p*****2
发帖数: 21240
30
来自主题: JobHunting版 - Java concurrency 面试题
想学习总结一下,大家说说有什么典型的题目呀?
刚看了H2O那个。还有producer/consumer, blocking queue。还有什么其他的吗?是不
是一般就是synchronized, wait notifyAll差不多就能解决了?
e***s
发帖数: 799
31
来自主题: JobHunting版 - Java concurrency 面试题
我的总结很初级。希望大牛们补充。
1.可以多读,写只能一个。但读写不能同时来。
2.要防止Starvation,比如他在single上用了一个writeRequest,有writeRequest的就不
能再进read了。
3.注意notify 和 notifyAll 的区别。
——————————————————————————————————————
——————————————————————————————————
4.适当允许reentrance,知道什么意思,但是觉得很难搞,不知道面试会不会要求。
5.防止deadlock这个我觉得在面试的时候基本用不到,因为很少lock一个以上的object
教程最后一章就是总结,二爷可以先看最后一章。
p*****2
发帖数: 21240
32
来自主题: JobHunting版 - Java concurrency 面试题

object
刚order了java concurrency in practice, 同时在看CC150相关章节,thinking in
java concurrency那章,以及effective java concurrency那章。简单列了一个提纲,
希望这周或者下周可以搞完。
1. How to create thread
implement Runnable
implement Callable
extends Thread
2. How to start thread
Thread pool
Thread.start
3. Synchronization
synchronized keyword
Lock
Semaphore
Immutability
volatile
java.util.concurrent.atomic
concurrent collection
4. Communiication
wait, notify, notifyall
Condition
concurrent collection
5. Common coding questions
bl... 阅读全帖
F****n
发帖数: 3271
33
来自主题: JobHunting版 - Java编程讨论:LinkedIn的H2O
public class H2O {
public static class ThreadHolder {
Thread thread;
ThreadHolder(Thread thread) {
this.thread = thread;
}
}
protected LinkedList hlist = new LinkedList();
protected LinkedList olist = new LinkedList();
public boolean h() {
ThreadHolder current = new ThreadHolder(Thread.currentThread());
synchronized (current) {
ThreadHolder[] threadsToWakeUp = null;
// updating the queues requires a global lock;
sy... 阅读全帖
F****n
发帖数: 3271
34
来自主题: JobHunting版 - Java编程讨论:LinkedIn的H2O
public class H2O {
public static class ThreadHolder {
Thread thread;
ThreadHolder(Thread thread) {
this.thread = thread;
}
}
protected LinkedList hlist = new LinkedList();
protected LinkedList olist = new LinkedList();
public boolean h() {
ThreadHolder current = new ThreadHolder(Thread.currentThread());
synchronized (current) {
ThreadHolder[] threadsToWakeUp = null;
// updating the queues requires a global lock;
sy... 阅读全帖
p*****3
发帖数: 488
35
来自主题: JobHunting版 - Java编程讨论:LinkedIn的H2O
是不是可以这么做:
在两个类里分别维护两个static violate counter
H.currentCounter/H.bar
O.currentCounter/O.bar
每次一个H或者O线程创建的时候付一个id = currentCounter++;
每一个线程创建的时候check counter 和 bar看看是不是有满足构成H2O的3个线程存在
,如果自己是其中之一的话忽略(好像题目是这么要求的), 如果有的话提高bar,H.bar
+= 2, O.bar += 1, 这段check和修改的代码要保护, 然后NotifyALL, 然后自己wait

其他线程从wait中醒来后check自己的id和bar, 如果bar > id, return 否则继续wait
n****e
发帖数: 678
36
来自主题: JobHunting版 - thread-safe blockingqueue
看过这个网页的implmentation,感觉codes 有点问题。 比如,还没有add element 就
先notifyAll了。
w****r
发帖数: 15252
37
来自主题: JobHunting版 - 问一道电面的os的题
A.notify()
B.notify()
or notifyall()
e***n
发帖数: 42
38
来自主题: JobHunting版 - LinkedIn 电面
第二题:
public class BlockingQueueImpl implements BlockingQueue{
Queue q = new LinkedList();
int cap = 10;
long timeOut = 1000;

@Override
public Object take() {

while(q.isEmpty()){
try {
this.wait(timeOut);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Object rst = q.poll();

this.notifyAll();

return rst;
}
@Overrid... 阅读全帖
D**C
发帖数: 6754
39
来自主题: JobHunting版 - 请教L家生成H2O水分子的题。
等我周二上班了写写看哈
加几个wait和notifyall就行,你在想想,我觉得可行

producer
S*********9
发帖数: 541
40
来自主题: JobHunting版 - 请教L家生成H2O水分子的题。
楼上的解法会starve。思路是对的,用java解的话就用wait/notifyAll。和read/write
lock大同小异。
D**C
发帖数: 6754
41
这都没法编译,wait/notify都要建立在一个object上面。
当然略加修改就可以了,我不觉得还需要check empty/full,只需要notify the
waiting process就可以了,没有waiting的,notifyall没有负效果
d******e
发帖数: 2265
42
来自主题: JobHunting版 - T a b l e a u 昂塞特面经
send 那个APi设计
思路1加messsage queue
但是这个不是api 设计级别的问题
另外一个思路就是解决backpressure问题。
Back-pressure
A means of flow-control, a way for consumers of data to notify a producer
about their current availability, effectively slowing down the upstream
source to match their consumption speeds. In the context of Akka Streams
back-pressure is always understood as non-blocking and asynchronous
简单的说,send Query过去,返回还能处理多少条数据。
具体实现。
如果是actor的话,好办的多, 可以push, 可以pull.可以定义消息,slow down or
speed up.
可以加LB,加多个processor.等等
你要... 阅读全帖
d******e
发帖数: 2265
43
来自主题: JobHunting版 - T a b l e a u 昂塞特面经
send 那个APi设计
思路1加messsage queue
但是这个不是api 设计级别的问题
另外一个思路就是解决backpressure问题。
Back-pressure
A means of flow-control, a way for consumers of data to notify a producer
about their current availability, effectively slowing down the upstream
source to match their consumption speeds. In the context of Akka Streams
back-pressure is always understood as non-blocking and asynchronous
简单的说,send Query过去,返回还能处理多少条数据。
具体实现。
如果是actor的话,好办的多, 可以push, 可以pull.可以定义消息,slow down or
speed up.
可以加LB,加多个processor.等等
你要... 阅读全帖
a*****s
发帖数: 1121
44
来自主题: JobHunting版 - workday onsite面经,已挂
上周五的onsitee,只刷过三道leetcode题目,硬着头皮上了。免得是大数据platform
组SMTS,挂了,不知道谁黑的。
一个俄国小哥:
比较热情, 先问了stack用linklist和array实现的优缺点,然后问了如何用二维数组
存储神经网络,比较耐心的引导类型,最后时间没有了,就只讨论了一下为什么这么做
。俺提出了一些可能的;
印度人:
上来很详细的问了以前的做的东西,HIVE如何转化成TEZ的,TEZ和MAPREDUCE的性能区
别,Slider提交任务需要那三个文件,我说就是三个json文件关于资源请求,可执行文
件等等,半年前作的实在记不清了,他解释说是metainfo.xml, 和两个json文件,俺
就极力说服他,please检查slider的apache JIRA buglist,现在俺还有几个ticket要
解决,他说他会。没让写code
一个国人伯克利小伙子:
随便问了问以前的项目,然后让做题, 给两个string,一个str1,一个str2,找出
str1里所有的str2
出现的第一个位置:比如ababab,ab那么返回数组[0,2,4]。先让写te... 阅读全帖
f*******r
发帖数: 976
45
来自主题: JobHunting版 - workday onsite面经,已挂
Move on. 祝LZ早日拿大offer

上周五的onsitee,只刷过三道leetcode题目,硬着头皮上了。免得是大数据platform
组SMTS,挂了,不知道谁黑的。
一个俄国小哥:
比较热情, 先问了stack用linklist和array实现的优缺点,然后问了如何用二维数组
存储神经网络,比较耐心的引导类型,最后时间没有了,就只讨论了一下为什么这么做
。俺提出了一些可能的;
印度人:
上来很详细的问了以前的做的东西,HIVE如何转化成TEZ的,TEZ和MAPREDUCE的性能区
别,Slider提交任务需要那三个文件,我说就是三个json文件关于资源请求,可执行文
件等等,半年前作的实在记不清了,他解释说是metainfo.xml, 和两个json文件,俺
就极力说服他,please检查slider的apache JIRA buglist,现在俺还有几个ticket要
解决,他说他会。没让写code
一个国人伯克利小伙子:
随便问了问以前的项目,然后让做题, 给两个string,一个str1,一个str2,找出
str1里所有的str2
出现的第一个位置:比如ababa... 阅读全帖
a*****s
发帖数: 1121
46
来自主题: JobHunting版 - workday onsite面经,已挂
dp的前提是:全局可以拆成可重复的局部,局部最优可以导致全局最优,其实也是
greedy algorithm的思想。
如果是5,2,1的话,个人认为是没有问题的,但是加入3.5就有问题了。不知道是不是
符合你的想法。
那个设计题,国人大哥直接跟俺说了时用wait和notifyall的,不含糊。个人觉得这位
大哥很值得俺尊敬。
h**********a
发帖数: 562
47
来自主题: JobHunting版 - workday onsite面经,已挂
5,2,1可以,换成别的数不可以,所有说,greedy不work啊!我们写代码当然要解决一
类问题啦:).换个数字比较说明问题,假如给你1,5,15,20和25,要想得到40,哪种组
合?按照greedy就是1个25,1个15,1个5,一共就是3个硬币。但是2个20的用的更少,2
个更少。所有必须遍历所有能凑成40的组合,才能得到最优。greedy给出的解,用的硬
币肯定比较少,但不一定是最少的。
另外你说的wait和notifyall,是个函数吗,还是就是个概念啊。如果是个概念,那比
如具体到linux下(我只知道linux下),就可以用semaphore,conditional virable的
sem_wait, sem_post, pthread_cond_wait什么的啊。和国人大哥说的似乎没有矛盾?
c********t
发帖数: 5706
48
来自主题: JobHunting版 - 再问一个blockingqueue的问题
原谅我再执着问一次。synchronized 等待状态是block,不需要唤醒, 和wait是有区别
的。notify是唤醒wait状态的。到底会不
会有enque, deque同时wait的时候呢?如果没有,那notify只会wake对方的莫个thread
, 我写了一个最简单的,没用
notifyAll, 用的notify. 这个也是每次只唤醒一个线程。但如果有enque,
deque同时wait,这代码会有应该有deadlock,但是测试了很多次,上百线程,也没有
发生deadlock. 请大牛们帮看看下面代码有问题吗?
public class BlockingQueue3 {
private Deque queue;
private int limit = 10;
public BlockingQueue3(int pLimit) {
limit = pLimit;
queue = new ArrayDeque<>();
}
public synchronized void put(T ite... 阅读全帖
c********t
发帖数: 5706
49
我总结了下面这些。
其实面试中multi-threading coding的题很少,一般是问一下基本概念。我简历上写了
multithreading, 但是很多次onsite,只被问过一次ReadWriteLock。
基本概念就是以下这些
synchronized, lock (ReentrantLock, ReadWriteLock), semaphore, condition,
atomic, mutex,wait, notify, notifyAll, condition.wait, condition.signal
这些概念最好都看看例子。
其次coding 题,准备好这三道题:ReadWriteLock, BlockingQueue, H2O
m******t
发帖数: 2416
50
来自主题: Java版 - Re: connection pool
There are still several issues left in the code:
1.why is it necessary to create a new thread every time to
make a new connection?
2.the free() method relies on one assumption that
the implementation class
of Connection implement equals() properly. Or busy connections
won't be released correctly.
3.the notifyAll() call in the middle of getConnection
doesn't make much sense, because the caller thread will keep
the lock and call getConnection again, while all other threads
wakened up will simply h
1 2 下页 末页 (共2页)