c**z 发帖数: 669 | 1 多线程题目请教
1. threads of a process share the same memory address, when one makes a
change to the process, the change is visible to other threads. Can you give
an example?
2. Visual studio里面的 call stack, 是存储的什么?
3。new int* p 在heap上的内存,
int b 是在 stack上的内存,
这个对于process来说是一样的还是不一样的? |
|
s******7 发帖数: 1758 | 2 我干java好几年了,还头次见到锁method local object的,local object 保存在 每
个thread自己的stack里面, 你锁起来有什么用,别的thread照样进来a++ |
|
b**********h 发帖数: 419 | 3 工作里用Spring 框架,把Thread都包装好了,
现在去面试的时候,multi-threading都是必问问题,
简单的synchronize还能应付得过去,
有的面试官往深里头问,notify的应用,如何debug多线程什么的,我就只懂得皮毛了
有什么好project练习多线程吗? |
|
发帖数: 1 | 4 Spring还能包装threading,不会吧。Spring基本没啥用,就是Reflection based DI有
点用,JDBC template也算一个。
Spring没有必要的话尽量不要碰,这个会直接把你带到沟里去。
multithreading直接用java的executorservice。比较特殊的情况才需要直接写thread
。 |
|
|
e**u 发帖数: 409 | 6 【 以下文字转载自 JobHunting 讨论区 】
发信人: ermu (hehe), 信区: JobHunting
标 题: solid C# Multi Threading developer in LA area
发信站: BBS 未名空间站 (Fri Nov 6 15:12:33 2009, 美东)
收到一个recruiter的询问
I have a client in LA area who needs a solid C# Multi Threading developer。
有兴趣的请站内联系 |
|
|
z*****7 发帖数: 888 | 8 MTB sram xo crankset.前几天出去骑之前上右脚蹬的时候没拧紧,结果骑半道上给蹬
掉了,蹲下来一看把右边那个洞里的thread吃掉了大概2/3的样子,然后这几天一直凑
合着用剩下的1/3倒也没事。今天推到车店里让人给看看,结果师傅说你这既是右脚又
是carbon,thread hole没法弄只能全换,而且最好赶紧换不然迟早fail and you will
get hurt。换的话shimano xt300多,sram xo400多,我有点崩溃。。。。。。有人有
过类似的经验么?这个钱我是不是省不了了?多谢 |
|
M****m 发帖数: 3243 | 9 我有个thread坏掉了,然后买了套crankset换,然后crank两边的thread都被我弄坏了
。。。治好扔给LBS处理。。。
所以,这个钱就不要省了吧。。。
will |
|
G***G 发帖数: 16778 | 10 其实考虑下面例子。
总和每年的工资,从1990年到2010年的。
假设windows计算机是单cpu,单core
如果只有一个thread, (我还不知道一个概念,就是什么是进程,什么是线程)
那么需要时间n
如果开thread,那么时间会小于n,比如2/3吗? |
|
t*******y 发帖数: 10477 | 11 LZ问的是多进程同步下载会不会快些;他的教授说单Core CPU无法通过多进程提高
Efficiency。这两者基本没有关系。
下载速度跟CPU是否efficient关系不大。cpu再不efficient,它99%的时间还
是在等待network IO。 时下的CPU时钟大致在2GZ左右。即每秒运行400万条指令
(以平均每条指令花费五个clock cycle计算)。
T1 line 是1.5Mb/sec, T3 是44Mb/sec, 最快的t4 是274Mb/sec。
甚至连USB2,也只有480Mb/sec。以每传送一个Byte为一个指令算的话
(实际上每条指令通过Direct memory access (DMA)可以搬运更多
Byte),连USB2都只有CPU速度的1/10。也就是说,你同时连10个USB2
到一单CoreCPU的Computer上,同时从这10个USB2 Drive上“download"
file 到Computer里,看起来这十个Download是在同步进行一样。一个单核
CPU就可以同时handle这么多高速IO。
现在想象一下,将这些个USB2 port... 阅读全帖 |
|
H******S 发帖数: 6011 | 12 是否说如果有消音器就套消音器上去,没有的话就把那个螺丝帽拧上?
我给我的px4买了个较长的barrel,beretta上说是给加threading用的枪管,如果我不
做barrel threading应该也没关系吧?正常使用也可以,不会造成损坏是不? |
|
a***8 发帖数: 4735 | 13 I went for the indian Eyebrow threading in the mall last week, the lady did
it too thin, and i am waiting for my
brow to grow back a bit. My experience is that threading is less painful than the waxing.
Ok, please forgive my bang, it is D.I. Y.
And my HM sweater for about $25. |
|
h***e 发帖数: 20195 | 14 【 以下文字转载自 Detective 讨论区 】
发信人: joycee (临河而羡鱼,不如归家结网), 信区: Detective
标 题: thread 50
发信站: BBS 未名空间站 (Sat Jun 19 00:43:36 2010, 美东)
发信人: yaz (柏林低温武警), 信区: Piebridge
标 题: thread 50
发信站: Unknown Space - 未名空间 (Tue Apr 27 23:37:07 2004) WWW-POST
yaz
就是拿了,也不能池浴。
在现在这个敏感时期,池浴一定要小心。
mrbean
even with tampax, you should not take bath.
bath can be harmful in this sensitive time
alias
wokao!!!! I fule you!
卫生巾,护妹妹
月事时节莫进水
洗澡也能坏宝贝
unless
The pad is to protect your little sister
When in period there should be |
|
C****n 发帖数: 2324 | 15 In a BBS system, do you like the way we are using in this BBS? Honestly, I
like it. But looks like most BBS system is collapsing all articles in a thread
together and expand the thread when you click it.
Which one is better?
Thanks, |
|
d****d 发帖数: 133 | 16 that's what I meant. wc doesn't need to be thread-safe if you write code
like
this. If it doesn't work, it has nothing to do with wc's thread-safety. |
|
o**d 发帖数: 11 | 17
I guess ditto try to prevent other program, instead of other
threads from accessing the file when it is written. Is it
right, ditto?
Synchronized method can claim lock on the object, but that
lock is only valid to the thread within the same
application.
My solution is to create a temp file in the system temp
directory. After finished writing, rename it.
I don't like global variable and there is no such thing in
Java( Probably you can simulate it). Besides, this solution
only works when the to-b |
|
g**y 发帖数: 983 | 18 【 以下文字转载自 Programming 讨论区,原文如下 】
发信人: grey (东北汉), 信区: Programming
标 题: 现在还有什么OS不是THREAD级调度的吗?
发信站: The unknown SPACE (Tue Feb 4 14:37:22 2003) WWW-POST
准备用JAVA编应用于MULTIPLE CPU SERVER的应用程序
多THREAD就足够了吧 |
|
m******t 发帖数: 2416 | 19
Why does it matter? If you pragram in Java, you'd be programming against
the threading interface in Java, which is supposed to simulate threads
even if the underlying OS doesn't support it. |
|
R*********t 发帖数: 217 | 20 if you have a multi-processors machine, of course you will download
a JVM whose multi-threading support utilizes underneath multi-processors,
otherwise, what is the point of multi-threading? |
|
o*a 发帖数: 229 | 21 1. public class X implements Runnable{
2. private int x;
3. private int y;
4.
5. public static void main(String[]args){
6. X that = new X();
7. (new Thread(that)).start();
8. (new Thread(that)).start();
9. }
10.
11. public void run(){
12. for (;;){
13. x++;
14. y++;
15. System.out.printIn(“x=” + x + “, y = ” + y); 16. }
17. }
18.}
What is the result?
A. Errors at lines 7 and 8 cause compilation to fail.
B. The program prints pairs of values for x and y that might not always be the
same on the sa |
|
g*****g 发帖数: 34805 | 22 To be more specific, the computing thread will process until no more data in
queue and then sleep itself. A notification will be fired when current entered
data is the only one in queue.
。
thread)平时处于idel。main
开始 |
|
c****r 发帖数: 185 | 23 Well, in server side, there should be a daemon thread listening to a
pre-defined port
with a server socket. When the server socket accepts, it will return a normal
socket.
Then the daemon uses another thread to handle the socket.
two
socket,比如说socket_1和socket_2在client中,同样在server一边有两个对应的socket
是 |
|
r***s 发帖数: 737 | 24 is the "something" calculated in the new thread?
if yes, do you need to wait for the thread to finish the calculation before
you can "return something"
if not, what's the point of doing all this? |
|
n*m 发帖数: 23 | 25
It can be calculated in the new thread. My sample is a typical asynchronous
call. So, you may get invalid value from the call since the new thread may not
finish.
However, there are many ways to get a "correct" value. Here is a sample
public class MyValue {
boolean ready=false;
int realvalue;
public boolean getReady() {
return ready;
}
public void setReady (boolean ready) {
this.ready = ready;
}
}
...
MainThread:
MyValue returnValue = myThread.run();
while |
|
e***g 发帖数: 158 | 26 guys, just learn the right way. Object.wait(), Object.notify(),
Thread.join(), etc. or check EDU.oswego.cs.dl.util.concurrent,
which will be in java 1.5 standard API.
btw, do not call Thread.run(). that's a normal sync method call! |
|
g***r 发帖数: 281 | 27 Runnable t = new Runnable() {
public void run()
{ //....
}
};
Thread t1 = new Thread (t);
t1.start();
这段code比较奇怪, 我以为应该是语法错, 但是却能运行,咋回事? |
|
y******e 发帖数: 7 | 28 Since multiple threads can have same name, so thread name cannot be used for
this purpose. Does anyone know any other means to achieve this?
3x much. |
|
w**i 发帖数: 80 | 29 In the Java class below, an instance of this class is created on each of 3 threads. I need some help to find any likely serious problem these threads will have with using the Calc mehtod. And what is a good solution?
public class doSomething {
private static int w = 1;
private int x = 1;
private static int y = 100;
private int z = 100;
public int Calc() {
int total = 0;
total = (w * y) + (x * z);
w = w + 1;
x = x + 1;
return (tot |
|
l****2 发帖数: 41 | 30 好像thread用不同的stack区分,那new thread()是占heap还是stack呢? |
|
m******t 发帖数: 2416 | 31 interrupt() only interrupts threads that are wait()'ing or sleep()'ing.
There are timeout values you can set on a URLConnection. Also thread2 needs
to be coded to cooperate with an "interrupt" request from main. |
|
h*********o 发帖数: 62 | 32 since you are using jre 1.6, using the new thread framework introduced from
1.5 would be a better idea.
You might want to have a look at futuretask, callable, executor framework,
etc. the new framework is much better than the old one in aspects of value
return, cancellation, interruption, and exception handling, etc.
As I remember, you should be able to find the code sample to your question
in the book of Java Concurrency... (sorry, forget the full name). The book
was written by the lead desig |
|
k***r 发帖数: 4260 | 33 Sounds like thread2 is blocking so it won't be able to
poll.
Another idea is for the main thread to check the result
in thread2 after 2 seconds. If it's not there, use null,
and let thread2 continue to run to finish, and ignore
the result.
both
method,once
status of |
|
Z****e 发帖数: 2999 | 34 Thread#interrupt is discouraged, and the right way is to ask thread2 exit
willfully via some flag. The core issue here is that the input stream on URL
object might block, so what you need is a timeout on the read.
see URLConnection class, which has timeout for both connect and read, and
you can obtain an instace from URL#openConnection. |
|
A**o 发帖数: 1550 | 35 thanks for explaining. but i doubt the logger per thread
model would work without make your own extentions.
anyway, i don't think your request is what log4j intends to do.
and from my experience, tempering with log4j other than config is not worthy.
how about dump everything into a db using jdbc appender,
and assign each thread with a uid and log it.
and when an error occurs,
dig the db, and query on the uid, and send your email? |
|
m******t 发帖数: 2416 | 36 The subject is wrong to begin with. The plain vanilla singleton
pattern doesn't have to do with thread-safety whatsoever, because
it's as simple as:
public class Singleton {
....private static final Singleton INSTANCE = new Singleton();
....private Singleton() {}
....public static getInstance() { return INSTANCE; }
}
The part where we put the initialization into getInstance() is
called Lazy Initialization, which is a separate pattern. And that's
where thread-safe might be a concern - only when r |
|
b******y 发帖数: 9224 | 37 最近在工作当中遇到一个网站的bug, 在本地机器上测试都没发现过。花了好几天,才
发现是java multi-threading的问题,有个method需要加synchronized. 其实貌似很多
这样的问题都是thread引起的。早就应该想到。debug还是挺有意思的,类似玩儿游戏
。比较challenging.发发感想:
http://www.jiansnet.com/topic?id=23308 |
|
m****r 发帖数: 6639 | 38 you can have have the file transfer thread wait for the db thread to finish,
and then continue to write the file, and roll back if file transfer fails.
since the db job should be fast, this might not be as bad as it sounds.
other
its |
|
m****r 发帖数: 6639 | 39 sorry. didn't mean "roll back". first thread need to commit right away.
and the second thread need to undo the commit. |
|
c******n 发帖数: 4965 | 40 在debug, 发现我的java code 在run 1000多threads
是否太多了? JVM supposedly 可以正常处理多少threads?
就是想要个大概的rule of thumb, 以后debug 的时候可以用到。 |
|
r*****l 发帖数: 2859 | 41 Use jstack dump thread. Then use TDA to analyze. Remember that thread
behavior is dynamic, so take multiple dumps and try to find the corelation. |
|
a******s 发帖数: 7 | 42 I have streaming data like
Type, Sequence
(A, 1)
(A, 2)
(B, 1)
(B, 2)
(A, 3)
...
For any given type, the incoming sequence is in order. Now we want to
process the above data as soon as possible, e.g print them out. But there is
one condition: for any type, the processing order must follow the sequence
order.
My initial idea is to create one queue and one processing thread for each
type. However, there are
thousands of types, then there will be too many threads. |
|
x****d 发帖数: 1766 | 43 ur use case is not clear, but anyway I don't see it is a case for using
multi thread.
let us say, you have been printing type A for 10 minutes, then switch
printing type B, how critical is the delay of processing type B?
In real world, there is no way you can delay processing type B that long.
there is many design books talks about using multi threading, but I don't
see yours is the case. |
|
r***e 发帖数: 2000 | 44 Since Linux does not support multiple threads within
one process, is a thread and a process basically the
same thing in Linux?
Does Windows support that? Any OS? |
|
l*****o 发帖数: 473 | 45 It didn't make sense at all to create many threads for computation intensive
tasks.
If you want to hide IO latency, then you maybe need it. Otherwise, there is
no use at all. BTW, switching between threads is light weight, but still you
need to pay overhead. |
|
g*****y 发帖数: 1120 | 46 现有一程序段,需要用到不同输入数据并发执行,
该程序需要instanciate一个c++ class, 该class即有全局static变量又有生成multi
threads
不知道这种情况下用multi-threading是否可能?
觉得用multi process编程更容易而且符合需要,但不知运行代价会不会很大。
还有就是现在已经找不到multi process的例子了。 |
|
p*u 发帖数: 2454 | 47 Please take a look at following Pseudocode. I don't think
it's thread-safe. any ideas how to make it thread-safe?
class A
{
public:
A() : ptr(NULL) { };
void startup(B b, int i)
{
static C c(i);
ptr = &c;
b.dostuff(ptr);
}
private:
const C * ptr;
};
class B
{
public:
B() { };
/*
* value that c points to is NOT copied,
* so it needs to stay valid during
* muliple invocations of dostuff |
|
l*****n 发帖数: 633 | 48 【 以下文字转载自 Linux 讨论区 】
发信人: luxilon (昵称不好起), 信区: Linux
标 题: 请帮忙看个thread的问题 (with memory dump)
发信站: BBS 未名空间站 (Mon Mar 5 18:26:04 2007), 转信
试着编了一个程序,有10多个pthreads同时运行,出现下面的错误,读不太懂,请帮忙
分析一下memory(stack, heap)。是不是分配给给个thread的stack太少了。该怎样调整?
thanks. |
|
s****l 发帖数: 137 | 49 我想把一个class里的几个member function分别作为单独的thread运行,有没有办法?
现有的方法好像要求把member function包装成C function,这样只能在C function中
create object,无法实现一个类管理多个thread了。是不是只能用C了? thanks. |
|
c***d 发帖数: 996 | 50 ☆─────────────────────────────────────☆
REM (REM) 于 (Thu Jan 11 13:46:17 2007) 提到:
if so, how?
an interview question. thanks.
☆─────────────────────────────────────☆
mxyzptlk (information) 于 (Thu Jan 11 13:55:32 2007) 提到:
wait for a resource already locked by itself before its release
if so, how?
an interview question. thanks.
☆─────────────────────────────────────☆
REM (REM) 于 (Thu Jan 11 14:06:26 2007) 提到:
if it's already locked by the thread ifself, why does the thread
need to |
|