Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
fba33087
Commit
fba33087
authored
Sep 22, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a thread pool exception
parent
3c79d031
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
407 additions
and
404 deletions
+407
-404
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+396
-383
ThreadUtils.java
...rc/main/java/us/codecraft/webmagic/utils/ThreadUtils.java
+8
-19
SpiderTest.java
...-core/src/test/java/us/codecraft/webmagic/SpiderTest.java
+3
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
fba33087
This diff is collapsed.
Click to expand it.
webmagic-core/src/main/java/us/codecraft/webmagic/utils/ThreadUtils.java
View file @
fba33087
package
us
.
codecraft
.
webmagic
.
utils
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.
LinkedBlocking
Queue
;
import
java.util.concurrent.
Synchronous
Queue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -11,22 +11,11 @@ import java.util.concurrent.TimeUnit;
*/
public
class
ThreadUtils
{
public
static
ExecutorService
newFixedThreadPool
(
int
threadSize
)
{
return
new
ThreadPoolExecutor
(
threadSize
,
threadSize
,
0L
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(
1
)
{
private
static
final
long
serialVersionUID
=
-
9028058603126367678L
;
@Override
public
boolean
offer
(
Runnable
e
)
{
try
{
put
(
e
);
return
true
;
}
catch
(
InterruptedException
ie
)
{
Thread
.
currentThread
().
interrupt
();
}
return
false
;
}
});
}
public
static
ExecutorService
newFixedThreadPool
(
int
threadSize
)
{
if
(
threadSize
<=
1
)
{
throw
new
IllegalArgumentException
(
"ThreadSize must be greater than 1!"
);
}
return
new
ThreadPoolExecutor
(
threadSize
-
1
,
threadSize
-
1
,
0L
,
TimeUnit
.
MILLISECONDS
,
new
SynchronousQueue
<
Runnable
>(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
}
}
webmagic-core/src/test/java/us/codecraft/webmagic/SpiderTest.java
View file @
fba33087
...
...
@@ -18,11 +18,12 @@ public class SpiderTest {
public
void
process
(
ResultItems
resultItems
,
Task
task
)
{
System
.
out
.
println
(
1
);
}
});
})
.
thread
(
2
)
;
spider
.
start
();
Thread
.
sleep
(
10000
);
spider
.
stop
();
// spider.run();
Thread
.
sleep
(
10000
);
spider
.
start
();
Thread
.
sleep
(
10000
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment