Skip to content

cyssxt/multithreading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multithreading(java 多线程)

a simple multi-thread utils

how to use it

AbstractTask abstractTask = new AbstractTask(){
    //just to do
    public void run(ThreadContext threadContext) {
        System.out.println("asdasd");
    }
    // how to run,if return ture,it will be run forever
    public boolean filter(){
        return true;
    }
};
ThreadManager threadManager = ThreadManager.getIntance(3,abstractTask);
//start thread list
threadManager.start();

how to use stack

for example:


// push into stack as a java object 
threadContext.getTaskShareMsg().push("cyssxt")//String

threadContext.getTaskShareMsg().push(new String[]{"cyssxt"})//String array

//pop with the first one
threadContext.getTaskShareMsg().pop()

stack is thread safe constructor

while two thread use push or pop at same time, another will in waiting list!

how to use key-value cache

same as stack:

first step(get instance of TaskShareMsg by threadContext):


TaskShareMsg taskShareMsg = threadContext.getTaskShareMsg();
taskShareMsg.push("name","cyssxt");

####get value by key


taskShareMsg.get("name");
************

About

多线程处理

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages