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
3c79d031
Commit
3c79d031
authored
Sep 22, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix thread pool
parent
81f75347
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
12 deletions
+6
-12
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+6
-5
Selectors.java
...c/main/java/us/codecraft/webmagic/selector/Selectors.java
+0
-5
UrlUtils.java
...e/src/main/java/us/codecraft/webmagic/utils/UrlUtils.java
+0
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
3c79d031
...
...
@@ -234,12 +234,15 @@ public class Spider implements Runnable, Task {
}
Request
request
=
scheduler
.
poll
(
this
);
//single thread
if
(
executorService
==
null
)
{
if
(
threadNum
<=
1
)
{
while
(
request
!=
null
&&
stat
.
compareAndSet
(
STAT_RUNNING
,
STAT_RUNNING
))
{
processRequest
(
request
);
request
=
scheduler
.
poll
(
this
);
}
}
else
{
synchronized
(
this
)
{
this
.
executorService
=
ThreadUtils
.
newFixedThreadPool
(
threadNum
);
}
//multi thread
final
AtomicInteger
threadAlive
=
new
AtomicInteger
(
0
);
while
(
true
&&
stat
.
compareAndSet
(
STAT_RUNNING
,
STAT_RUNNING
))
{
...
...
@@ -363,10 +366,11 @@ public class Spider implements Runnable, Task {
public
void
stop
()
{
stat
.
compareAndSet
(
STAT_RUNNING
,
STAT_STOPPED
);
executorService
.
shutdown
();
}
public
void
stopAndDestroy
()
{
st
at
.
compareAndSet
(
STAT_RUNNING
,
STAT_STOPPED
);
st
op
(
);
destroy
();
}
...
...
@@ -385,9 +389,6 @@ public class Spider implements Runnable, Task {
if
(
threadNum
==
1
)
{
return
this
;
}
synchronized
(
this
)
{
this
.
executorService
=
ThreadUtils
.
newFixedThreadPool
(
threadNum
);
}
return
this
;
}
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/selector/Selectors.java
View file @
3c79d031
...
...
@@ -44,9 +44,4 @@ public abstract class Selectors {
return
new
OrSelector
(
selectors
);
}
public
static
void
main
(
String
[]
args
)
{
String
s
=
"a"
;
or
(
regex
(
"<title>(.*)</title>"
),
xpath
(
"//title"
),
$
(
"title"
)).
select
(
s
);
}
}
\ No newline at end of file
webmagic-core/src/main/java/us/codecraft/webmagic/utils/UrlUtils.java
View file @
3c79d031
...
...
@@ -16,8 +16,6 @@ import java.util.regex.Pattern;
*/
public
class
UrlUtils
{
private
static
Pattern
relativePathPattern
=
Pattern
.
compile
(
"^([\\.]+)/"
);
/**
* canonicalizeUrl
*
...
...
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