由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 问个HttpClient 的问题
相关主题
paint()呀,repaint()呀question on single thread & multithread
a Java MultiThreading questionsuggestions needed
急问:怎么kill一个thread, thread.interrupte()不好用呀?AtomicInteger和volatile int有啥区别
一道java题java ,wait ,notify notifyall
Apply lock on a class.jdbc + oracle connection pooling问题
怎么可以练习多线程编程呢?问一个关于access object instance的问题
soap questions, continuesHelp!! a cookie question
Java synchronized method一问[转载] Re: 觉得自己很笨
相关话题的讨论汇总
话题: httpclient话题: get话题: connection话题: thread2话题: thread1
进入Java版参与讨论
1 (共1页)
s******d
发帖数: 901
1
第一次用http protocol, 不太熟,想问一下,我写的是client side, 如果我需要两个
thread, thread1 is just doing regular basis GET request and read the
response in a while loop. Thread2 needs to send GET request once and keep
the connection open and read the response stream continuously.(别问为什么,
不是我design的) Do I need two HttpClient instances? Because I'm afraid if I
only create one HttpClient, it will reuse the connection, then thread1 will
be blocked by thread2 since it never ends reading the data. If I create two
HttpClient
a****i
发帖数: 1182
2
If I were you, I will use two instances of HttpClient.
what you need be aware of depends on the data you are going to
send and receive, I guess
in short, be careful of the stuffs need be synchronized

I
will
two
connection

【在 s******d 的大作中提到】
: 第一次用http protocol, 不太熟,想问一下,我写的是client side, 如果我需要两个
: thread, thread1 is just doing regular basis GET request and read the
: response in a while loop. Thread2 needs to send GET request once and keep
: the connection open and read the response stream continuously.(别问为什么,
: 不是我design的) Do I need two HttpClient instances? Because I'm afraid if I
: only create one HttpClient, it will reuse the connection, then thread1 will
: be blocked by thread2 since it never ends reading the data. If I create two
: HttpClient

s******d
发帖数: 901
3
thanks, I'll try when the backend is ready. Data synchronization should not
be a concern so far, I only worry about sending/receiving data through
separate threads will interfere each other.
So can I assume that each HttpClient will establish one http connection?

【在 a****i 的大作中提到】
: If I were you, I will use two instances of HttpClient.
: what you need be aware of depends on the data you are going to
: send and receive, I guess
: in short, be careful of the stuffs need be synchronized
:
: I
: will
: two
: connection

m******t
发帖数: 2416
4
I don't see why you can't use MultiThreadedConnectionManager with
different configurations.

not

【在 s******d 的大作中提到】
: thanks, I'll try when the backend is ready. Data synchronization should not
: be a concern so far, I only worry about sending/receiving data through
: separate threads will interfere each other.
: So can I assume that each HttpClient will establish one http connection?

s******d
发帖数: 901
5
Ok, I see some sample code like the following. So if I do this and use one
instance of httpClient for both threads, after both threads sends GET
requests, one thread is reading responds, the other one won't be blocked?
releasing the connection in one thread will not affect other threads?
public void createHttpClient() {
connectionManager = new MultiThreadedHttpConnectionManager();
final HttpConnectionManagerParams cmp = connectionManager.getParams();
cmp.setStaleCheckingEnabled(staleCheckingEnab

【在 m******t 的大作中提到】
: I don't see why you can't use MultiThreadedConnectionManager with
: different configurations.
:
: not

m******t
发帖数: 2416
6
I think this looks fine. You'll have to try it yourself though.

【在 s******d 的大作中提到】
: Ok, I see some sample code like the following. So if I do this and use one
: instance of httpClient for both threads, after both threads sends GET
: requests, one thread is reading responds, the other one won't be blocked?
: releasing the connection in one thread will not affect other threads?
: public void createHttpClient() {
: connectionManager = new MultiThreadedHttpConnectionManager();
: final HttpConnectionManagerParams cmp = connectionManager.getParams();
: cmp.setStaleCheckingEnabled(staleCheckingEnab

a****i
发帖数: 1182
7
why bother? I think that just likes you open two browsers

【在 s******d 的大作中提到】
: Ok, I see some sample code like the following. So if I do this and use one
: instance of httpClient for both threads, after both threads sends GET
: requests, one thread is reading responds, the other one won't be blocked?
: releasing the connection in one thread will not affect other threads?
: public void createHttpClient() {
: connectionManager = new MultiThreadedHttpConnectionManager();
: final HttpConnectionManagerParams cmp = connectionManager.getParams();
: cmp.setStaleCheckingEnabled(staleCheckingEnab

1 (共1页)
进入Java版参与讨论
相关主题
[转载] Re: 觉得自己很笨Apply lock on a class.
Re: Display, edit, and save Image on HTM怎么可以练习多线程编程呢?
java怎么display web pagesoap questions, continues
which http client package is good to use?Java synchronized method一问
paint()呀,repaint()呀question on single thread & multithread
a Java MultiThreading questionsuggestions needed
急问:怎么kill一个thread, thread.interrupte()不好用呀?AtomicInteger和volatile int有啥区别
一道java题java ,wait ,notify notifyall
相关话题的讨论汇总
话题: httpclient话题: get话题: connection话题: thread2话题: thread1