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
5f9e1a96
Commit
5f9e1a96
authored
Nov 17, 2015
by
Yihua Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #233 from x1ny/master
修正FileCacheQueueScheduler导致程序不能正常结束和未关闭流
parents
7d7eb033
90e14b31
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+1
-0
FileCacheQueueScheduler.java
...codecraft/webmagic/scheduler/FileCacheQueueScheduler.java
+13
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
5f9e1a96
...
...
@@ -374,6 +374,7 @@ public class Spider implements Runnable, Task {
public
void
close
()
{
destroyEach
(
downloader
);
destroyEach
(
pageProcessor
);
destroyEach
(
scheduler
);
for
(
Pipeline
pipeline
:
pipelines
)
{
destroyEach
(
pipeline
);
}
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler.java
View file @
5f9e1a96
...
...
@@ -12,17 +12,19 @@ import java.util.Set;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* Store urls and cursor in files so that a Spider can resume the status when shutdown.<br>
*
* @author code4crafter@gmail.com <br>
* @since 0.2.0
*/
public
class
FileCacheQueueScheduler
extends
DuplicateRemovedScheduler
implements
MonitorableScheduler
{
public
class
FileCacheQueueScheduler
extends
DuplicateRemovedScheduler
implements
MonitorableScheduler
,
Closeable
{
private
String
filePath
=
System
.
getProperty
(
"java.io.tmpdir"
);
...
...
@@ -43,6 +45,8 @@ public class FileCacheQueueScheduler extends DuplicateRemovedScheduler implement
private
BlockingQueue
<
Request
>
queue
;
private
Set
<
String
>
urls
;
private
ScheduledExecutorService
flushThreadPool
;
public
FileCacheQueueScheduler
(
String
filePath
)
{
if
(!
filePath
.
endsWith
(
"/"
)
&&
!
filePath
.
endsWith
(
"\\"
))
{
...
...
@@ -94,7 +98,8 @@ public class FileCacheQueueScheduler extends DuplicateRemovedScheduler implement
}
private
void
initFlushThread
()
{
Executors
.
newScheduledThreadPool
(
1
).
scheduleAtFixedRate
(
new
Runnable
()
{
flushThreadPool
=
Executors
.
newScheduledThreadPool
(
1
);
flushThreadPool
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
public
void
run
()
{
flush
();
...
...
@@ -161,6 +166,12 @@ public class FileCacheQueueScheduler extends DuplicateRemovedScheduler implement
}
}
}
public
void
close
()
throws
IOException
{
flushThreadPool
.
shutdown
();
fileUrlWriter
.
close
();
fileCursorWriter
.
close
();
}
private
String
getFileName
(
String
filename
)
{
return
filePath
+
task
.
getUUID
()
+
filename
;
...
...
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