Redian新闻
>
question on single thread & multithread
avatar
question on single thread & multithread# Java - 爪哇娇娃
g*n
1
Hello everyone,
I am new to Java and have to ask a simple question.
I am writing a program that has two sockets s1 and s2.
s1 listens to a single client and uses a single thread
s2 listens to possible multiple clients and uses a multithread to track number
of connections, by group.activeCount();
It requires both the single thread and multithread run at the same time. And
the multithread's group.activeCount() needs to be passed to the single thread
every time a thread in the multithread starts or
avatar
c*e
2
Try the following code and you'll see why.
For primitive types, java just copy the value
(instead of passing the reference of that object)
when passing parameters.
class t {
private static void modify(int val)
{
val += 1;
System.out.println("Value of integer inside: "+val);
}
public static void main(String []args){
int t = 0;
modify(t);
System.out.println("Value of integer outside: "+t);
}
}

number
thread
is

【在 g****n 的大作中提到】
: Hello everyone,
: I am new to Java and have to ask a simple question.
: I am writing a program that has two sockets s1 and s2.
: s1 listens to a single client and uses a single thread
: s2 listens to possible multiple clients and uses a multithread to track number
: of connections, by group.activeCount();
: It requires both the single thread and multithread run at the same time. And
: the multithread's group.activeCount() needs to be passed to the single thread
: every time a thread in the multithread starts or

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。