does akka actor is sequence
I have a task that requires a thread pool, and each task needs to be executed in the same order as the call. So I used akka actor, but it not work as my expected, then I did a test.
Here is my code:
@Test
def actorTest1(): Unit = {
for (i <- 1 to 300) {
val actorRef: ActorRef = actorFactory.createActor("myActor")
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
@Test
def actorTest2(): Unit = {
val actorRef: ActorRef = actorFactory.createActor("myActor")
for (i <- 1 to 300) {
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
case tell: Tell => {
Thread.Sleep(900)
log.debug("tell: " + tell.i)
}
The log of test1, it's sequence is not as 1, 2, 3, 4, 5..., with different thread; case the test2's is 1, 2, 3, 4, 5..., but test2 always use the same thread. I want it work as the log is sequence with different thread, like:
2018-11-22 20:13:19.280 DEBUG 14176 --- [thread-1] : tell: 70
2018-11-22 20:13:19.857 DEBUG 14176 --- [thread-2] : tell: 71
2018-11-22 20:13:20.362 DEBUG 14176 --- [thread-3] : tell: 72
2018-11-22 20:13:20.823 DEBUG 14176 --- [thread-4] : tell: 73
akka actor
add a comment |
I have a task that requires a thread pool, and each task needs to be executed in the same order as the call. So I used akka actor, but it not work as my expected, then I did a test.
Here is my code:
@Test
def actorTest1(): Unit = {
for (i <- 1 to 300) {
val actorRef: ActorRef = actorFactory.createActor("myActor")
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
@Test
def actorTest2(): Unit = {
val actorRef: ActorRef = actorFactory.createActor("myActor")
for (i <- 1 to 300) {
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
case tell: Tell => {
Thread.Sleep(900)
log.debug("tell: " + tell.i)
}
The log of test1, it's sequence is not as 1, 2, 3, 4, 5..., with different thread; case the test2's is 1, 2, 3, 4, 5..., but test2 always use the same thread. I want it work as the log is sequence with different thread, like:
2018-11-22 20:13:19.280 DEBUG 14176 --- [thread-1] : tell: 70
2018-11-22 20:13:19.857 DEBUG 14176 --- [thread-2] : tell: 71
2018-11-22 20:13:20.362 DEBUG 14176 --- [thread-3] : tell: 72
2018-11-22 20:13:20.823 DEBUG 14176 --- [thread-4] : tell: 73
akka actor
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52
add a comment |
I have a task that requires a thread pool, and each task needs to be executed in the same order as the call. So I used akka actor, but it not work as my expected, then I did a test.
Here is my code:
@Test
def actorTest1(): Unit = {
for (i <- 1 to 300) {
val actorRef: ActorRef = actorFactory.createActor("myActor")
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
@Test
def actorTest2(): Unit = {
val actorRef: ActorRef = actorFactory.createActor("myActor")
for (i <- 1 to 300) {
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
case tell: Tell => {
Thread.Sleep(900)
log.debug("tell: " + tell.i)
}
The log of test1, it's sequence is not as 1, 2, 3, 4, 5..., with different thread; case the test2's is 1, 2, 3, 4, 5..., but test2 always use the same thread. I want it work as the log is sequence with different thread, like:
2018-11-22 20:13:19.280 DEBUG 14176 --- [thread-1] : tell: 70
2018-11-22 20:13:19.857 DEBUG 14176 --- [thread-2] : tell: 71
2018-11-22 20:13:20.362 DEBUG 14176 --- [thread-3] : tell: 72
2018-11-22 20:13:20.823 DEBUG 14176 --- [thread-4] : tell: 73
akka actor
I have a task that requires a thread pool, and each task needs to be executed in the same order as the call. So I used akka actor, but it not work as my expected, then I did a test.
Here is my code:
@Test
def actorTest1(): Unit = {
for (i <- 1 to 300) {
val actorRef: ActorRef = actorFactory.createActor("myActor")
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
@Test
def actorTest2(): Unit = {
val actorRef: ActorRef = actorFactory.createActor("myActor")
for (i <- 1 to 300) {
actorRef ! Tell(i)
}
Thread.sleep(6000000)
}
case tell: Tell => {
Thread.Sleep(900)
log.debug("tell: " + tell.i)
}
The log of test1, it's sequence is not as 1, 2, 3, 4, 5..., with different thread; case the test2's is 1, 2, 3, 4, 5..., but test2 always use the same thread. I want it work as the log is sequence with different thread, like:
2018-11-22 20:13:19.280 DEBUG 14176 --- [thread-1] : tell: 70
2018-11-22 20:13:19.857 DEBUG 14176 --- [thread-2] : tell: 71
2018-11-22 20:13:20.362 DEBUG 14176 --- [thread-3] : tell: 72
2018-11-22 20:13:20.823 DEBUG 14176 --- [thread-4] : tell: 73
akka actor
akka actor
edited Nov 23 '18 at 2:23
西门吹雪
asked Nov 22 '18 at 12:16
西门吹雪西门吹雪
488
488
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52
add a comment |
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430831%2fdoes-akka-actor-is-sequence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430831%2fdoes-akka-actor-is-sequence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why do you want it? In actorTest2, there is a single actor which works from time to time. There is no difference whether it works on the same thread or on different threads.
– Alexei Kaigorodov
Nov 22 '18 at 15:19
I edited my question, I mean, if it's on the same thread, there is no need to use threads(actor).
– 西门吹雪
Nov 23 '18 at 3:55
"I want it work as the log is sequence with different thread" - sorry, I do not understand what you want, because this is an incorrect sentence.
– Alexei Kaigorodov
Nov 23 '18 at 4:55
Just like executed as actor ! Tell(1), actor ! Tell(2), actor ! Tell(3), actor ! Tell(4)... and in the controller, the log is thread-1: tell: 1, thread-2: tell: 2, thread-3: tell: 3, thread-4: tell: 4... the thread is different(thread-1,2,3,4...), and param received is tell :1,2,3,4...
– 西门吹雪
Nov 23 '18 at 5:38
executor chooses first available thread. All threads are equal. You should not bother which thread runs this or that actor. You cannot control this because it has no sense.
– Alexei Kaigorodov
Nov 23 '18 at 7:52