Topic: 如何解决一个Socket和线程问题?

  Print this page

1.如何解决一个Socket和线程问题? Copy to clipboard
Posted by: 迸泉
Posted on: 2005-11-16 20:08

本人最近做一个网页检索程序,采取多线程搜索,但要求将荡下来的信息存到一个局域网内另一台机器上的数据库,也就是分布式的。本人采取Socket把信息传给异地数据库。搜索程序放在服务器端。但本人在检索程序中用了30个线程进行爬网,荡下信息后用Socket传,数据库端采用单线程的程序监听信息。本人发现,原先爬网的程序速度变慢很多很多,而且数据库端信息不都是可以获取的。不知道是否应该在数据库端也采用多线程?应如何做?
有经验的兄弟请多指教,本人邮箱:qianyiqqq@hotmail.com

2.Re:如何解决一个Socket和线程问题? [Re: 迸泉] Copy to clipboard
Posted by: ftang
Posted on: 2005-11-18 06:47

when you say :异地数据库, is that means Database? if it is a database why is socket connection not JDBC connection?
assume the 异地数据库 u mean is not real database just another "Server" that has ServerSocket listien on the certain port, in this case, when the ServerSocket get anything from client, is should create a woking thread(a worker) to process the information it got. otherwise....there will be a bottlenect at server side.

3.Re:如何解决一个Socket和线程问题? [Re: 迸泉] Copy to clipboard
Posted by: 迸泉
Posted on: 2005-11-20 17:30

有没有这种情况,client这端有多个线程通过Socket发数据,而那边接受方只有一个线程接受,会出现数据被冲掉无法接受的现象吗?

4.Re:如何解决一个Socket和线程问题? [Re: 迸泉] Copy to clipboard
Posted by: onsofts
Posted on: 2005-11-21 12:18

The data won't be gone if you used Synchronized keyword.

5.Re:如何解决一个Socket和线程问题? [Re: 迸泉] Copy to clipboard
Posted by: ftang
Posted on: 2005-12-09 04:44

at the client side:
different threads using same socket, the answer is yes, the datas will "OVERLAP" each other.. you sniffer the network, you will see your datas get massed up.
different threads using different socket the answer is no, the datas will "OVERLAP" until...until...at the server side you(your code) messed up.

ps to onsofts: "Synchronized" is "synchronized" with low case s, and please give advices after you konw what are you talking about...which synchronized is not a solution here..


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923