使用线程池管理线程,新增worker_threads参数
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
"server_port": "25565",
|
||||
"proxy_url": "",
|
||||
"username_prefix": "test",
|
||||
"worker_threads": 100,
|
||||
"count": 300,
|
||||
"reco_words": ["验证程序已启用","AntiAttack"],
|
||||
"login_commands": ["reg helloa helloa"],
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Configuration {
|
||||
spam_file: String,
|
||||
spam_delay_ms: i32,
|
||||
random_prefix: bool,
|
||||
pub worker_threads: i32
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
@@ -56,6 +57,7 @@ impl Configuration {
|
||||
spam_file: "".to_string(),
|
||||
spam_delay_ms: 0,
|
||||
random_prefix: false,
|
||||
worker_threads: 100
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
39
src/main.rs
39
src/main.rs
@@ -9,7 +9,7 @@ use reqwest;
|
||||
use serde_json::Value;
|
||||
// use tokio::task;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
// use std::thread;
|
||||
use tokio::sync::Mutex;
|
||||
use crate::utils::generate_username;
|
||||
use crate::configuration::Configuration;
|
||||
@@ -43,12 +43,12 @@ async fn main() {
|
||||
spam_cursor: Arc::new(Mutex::new(0))
|
||||
});
|
||||
|
||||
// let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
// .enable_all()
|
||||
// .thread_stack_size(8 * 1024 * 1024)
|
||||
// .worker_threads((configuration_rc.count()-1) as usize)
|
||||
// .build()
|
||||
// .unwrap();
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.thread_stack_size(8 * 1024 * 1024)
|
||||
.worker_threads(configuration_rc.worker_threads as usize)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
for _ in 0..configuration_rc.count() -1 {
|
||||
let lock_clone = thread_lock.clone();
|
||||
@@ -59,18 +59,19 @@ async fn main() {
|
||||
// println!("[MAIN] Thread {} created", i);
|
||||
// });
|
||||
// 生成一个线程
|
||||
// let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
|
||||
let handle = thread::spawn(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.thread_stack_size(8 * 1024 * 1024)
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
attack_thread(lock_clone,configuration_rc_clone,variables_clone).await;
|
||||
// println!("[MAIN] Thread {} created", i);
|
||||
});
|
||||
});
|
||||
// let handle = tokio::task::spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
|
||||
let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
|
||||
// let handle = thread::spawn(move || {
|
||||
// tokio::runtime::Builder::new_current_thread()
|
||||
// .enable_all()
|
||||
// .thread_stack_size(8 * 1024 * 1024)
|
||||
// .build()
|
||||
// .unwrap()
|
||||
// .block_on(async move {
|
||||
// attack_thread(lock_clone,configuration_rc_clone,variables_clone).await;
|
||||
// // println!("[MAIN] Thread {} created", i);
|
||||
// });
|
||||
//});
|
||||
handles.push(handle);
|
||||
// println!("[MAIN] Thread {} created", i) // 这个太吵了(
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user