RAG混合检索实战:语义与关键词协同提升召回准确率
2026/6/12 6:26:59
classRunnableDemoimplementsRunnable{privateStringthreadName;RunnableDemo(Stringname){threadName=name;System.out.println("Creating "+threadName);}@Overridepublicvoidrun(){System.out.println("Running "+threadName);try{for(inti=3;i>0;i--){System.out.println("Thread: "+threadName+", "+i);// 让线程睡眠一会Thread.sleep(50);}}catch(InterruptedExceptione){System.out.println("Thread "+threadName+" interrupted.");}System.out.println("Thread "+threadName+" exiting.");}}RunnableDemor1=newRunnableDemo("Thread-1");newThread(r1).start();classThreadDemoextendsThread{privateStringthreadName;ThreadDemo(Stringname){threadName=name;System.out.println("Creating "+threadName);}@Overridepublicvoidrun(){System.out.println("Running "+threadName);try{for(inti=3;i>0;i--){System.out.println("Thread: "+threadName+", "+i);// 让线程睡眠一会Thread.sleep(50);}}catch(InterruptedExceptione){System.out.println("Thread "+threadName+" interrupted.");}System.out.println("Thread "+threadName+" exiting.");}}ThreadDemothread=newThreadDemo("Thread-1");thread.start();publicclassCallableFutureTestimplementsCallable<Integer>{publicstaticvoidmain(String[]args){CallableFutureTestctt=newCallableFutureTest();FutureTask<Integer>ft=newFutureTask<>(ctt);for(inti=0;i<100;i++){System.out.println(Thread.currentThread().getName()+" 的循环变量i的值:"+i);if(i==20){newThread(ft,"Callable call").start();}}try{System.out.println("子线程的返回值:"+ft.get());}catch(InterruptedExceptione){e.printStackTrace();}catch(ExecutionExceptione){e.printStackTrace();}}@OverridepublicIntegercall()throwsException{inti=0;for(;i<100;i++){System.out.println(Thread.currentThread().getName()+" "+i);}returni;}}ExecutorServiceexecutor=Executors.newFixedThreadPool(2);Future<?>future=executor.submit(()->{System.out.println("Task is running");});executor.execute(()->{System.out.println("Task executed");});executor.shutdown();List<Runnable>notExecutedTasks=executor.shutdownNow();executor.awaitTermination(10,TimeUnit.SECONDS);importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;publicclassThreadPoolExample{publicstaticvoidmain(String[]args){ExecutorServiceexecutor=Executors.newFixedThreadPool(5);for(inti=0;i<10;i++){executor.execute(()->{System.out.println("线程执行任务");});}executor.shutdown();}}ExecutorServiceexecutor=Executors.newFixedThreadPool(2);Future<String>future=executor.submit(()->{Thread.sleep(1000);return"Task completed";});try{Stringresult=future.get();// 阻塞直到任务完成System.out.println(result);}catch(Exceptione){e.printStackTrace();}executor.shutdown();synchronized(对象){需要被同步的代码}classCounter{privateintcount=0;// 同步方法publicsynchronizedvoidincrement(){count++;}}importjava.util.concurrent.locks.Lock;importjava.util.concurrent.locks.ReentrantLock;classCounter{privateintcount=0;privateLocklock=newReentrantLock();publicvoidincrement(){lock.lock();// 加锁try{count++;}finally{lock.unlock();// 释放锁}}}