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
35288787
Commit
35288787
authored
Oct 31, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove shutdown call
parent
a3f9ad19
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+21
-10
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
35288787
...
...
@@ -74,6 +74,8 @@ public class Spider implements Runnable, Task {
protected
AtomicInteger
stat
=
new
AtomicInteger
(
STAT_INIT
);
protected
boolean
exitWhenComplete
=
false
;
protected
final
static
int
STAT_INIT
=
0
;
protected
final
static
int
STAT_RUNNING
=
1
;
...
...
@@ -240,7 +242,7 @@ public class Spider implements Runnable, Task {
while
(!
Thread
.
currentThread
().
isInterrupted
()
&&
stat
.
get
()
==
STAT_RUNNING
)
{
Request
request
=
scheduler
.
poll
(
this
);
if
(
request
==
null
)
{
if
(
threadAlive
.
get
()
==
0
)
{
if
(
threadAlive
.
get
()
==
0
&&
exitWhenComplete
)
{
break
;
}
// when no request found but some thread is alive, sleep a
...
...
@@ -258,7 +260,7 @@ public class Spider implements Runnable, Task {
try
{
processRequest
(
requestFinal
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"download "
+
requestFinal
+
" error"
,
e
);
logger
.
error
(
"download "
+
requestFinal
+
" error"
,
e
);
}
finally
{
threadAlive
.
decrementAndGet
();
}
...
...
@@ -372,20 +374,12 @@ public class Spider implements Runnable, Task {
public
void
stop
()
{
if
(
stat
.
compareAndSet
(
STAT_RUNNING
,
STAT_STOPPED
))
{
if
(
executorService
!=
null
)
{
executorService
.
shutdown
();
}
logger
.
info
(
"Spider "
+
getUUID
()
+
" stop success!"
);
}
else
{
logger
.
info
(
"Spider "
+
getUUID
()
+
" stop fail!"
);
}
}
public
void
stopAndDestroy
()
{
stop
();
destroy
();
}
/**
* start with more than one threads
*
...
...
@@ -413,6 +407,23 @@ public class Spider implements Runnable, Task {
EnvironmentUtil
.
setUseXsoup
(
false
);
}
public
boolean
isExitWhenComplete
()
{
return
exitWhenComplete
;
}
/**
* Exit when complete. <br/>
* True: exit when all url of the site is downloaded. <br/>
* False: not exit until call stop manually.<br/>
*
* @param exitWhenComplete
* @return
*/
public
Spider
setExitWhenComplete
(
boolean
exitWhenComplete
)
{
this
.
exitWhenComplete
=
exitWhenComplete
;
return
this
;
}
@Override
public
String
getUUID
()
{
if
(
uuid
!=
null
)
{
...
...
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