天天看點

首選線程池,而不是多線程; 建立線程的方法; 存儲過程和for循環插入資料; String字元串一般有什麼方法?面向對象怎麼了解?資料庫排序?左連接配接 ?右連接配接?jQuery是什麼?SpringBoot

首選線程池,而不是多線程

首選線程池,而不是多線程

/**

  • corePoolSize:線程長期為維持線程數 核心線程數,常用線程數
  • maximumPoolSize:線程數的上限,最大線程數
  • keepAliveTime:超過線程時長:60s
  • unit 時間機關
  • workQueue 阻塞隊列
  • threadFactory 線程工廠 可以為線程建立時起個好名字
  • handler 拒絕政策 四種
  • 任務的排隊隊列:ArrayBlockingQueue是一個阻塞式的隊列,一個基于數組的阻塞隊列:先進先出,有界隊列,隊列不支援空元素
•  */
 private static ExecutorService executor = new ThreadPoolExecutor(10, 10,
 60L, TimeUnit.SECONDS, new ArrayBlockingQueue(10));      
//ex:2
 private static ThreadFactory threadFactory = new ThreadFactoryBuilder().build();
 private static ExecutorService executorService = new ThreadPoolExecutor(10, 10,
 60L, TimeUnit.SECONDS, new ArrayBlockingQueue(10),
 threadFactory, new ThreadPoolExecutor.AbortPolicy());      

建立線程的方法

建立線程的方法

通過實作 Runnable 接口;

通過繼承 Thread 類本身;

通過 Callable 和 Future 建立線程。

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ReportApplication.class)
public class LocalCacheTest {
@Test
public void test() throws InterruptedException {
    RunnableDemo R1 = new RunnableDemo("11111");
    R1.start();
    R1.start();
    R1.start();
    R1.start();
    R1.start();
    R1.start();
    R1.start();
    R1.start();
}

//通過實作Runnable接口建立線程
class RunnableDemo implements Runnable {
    private Thread t;
    private String threadName;

    RunnableDemo(String name) {
        threadName = name;
        System.out.println("creating " + threadName);
    }


    @Override
    public void run() {
        System.out.println("Running " + threadName);
        for (int i = 4; i > 0; i--) {
            System.out.println("Thread: " + threadName + "," + i);
        }
        System.out.println("Thread " + threadName + " exiting.");
    }

    public void start() {
        System.out.println("Staring " + threadName);
        if (t == null) {
            t = new Thread(this, threadName);
            t.start();
        }
    }


}


//通過實作Runnable接口建立線程
class DisplayMessage implements Runnable {

    private String message;

    public DisplayMessage(String message) {
        this.message = message;
    }

    @Override
    public void run() {
        while (true) {
            System.out.println(message);
        }
    }
}

//繼承Thread類建立線程
class GuessANumber extends Thread {
    private int number;
    public GuessANumber(int number) {
        this.number = number;
    }

    public void run() {
        System.out.println("繼承Thread建立線程" + number);
    }
}

@Test
public void threadDemo() {

    System.out.println("Starting thread3...");
    Thread thread3 = new GuessANumber(27);
    thread3.start();
    try {
        thread3.join();
    } catch (InterruptedException e) {
        System.out.println("Thread interrupted");

    }

    System.out.println("Starting thread4...");
    Thread thread4 = new GuessANumber(75);
    thread4.start();

    Thread thread5 = new GuessANumber(5);
    thread5.start();

    Thread thread6 = new GuessANumber(6);
    thread6.start();

    Thread thread7 = new GuessANumber(7);
    thread7.start();

    Thread thread8 = new GuessANumber(8);
    thread8.start();

    System.out.println("main() is ending...");

}



//通過Callable和Future建立線程
class CallableThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int i = 0;
        for (; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
        return i;
    }
}

@Test
public void callableTest() {
    CallableThread ctt = new CallableThread();
    FutureTask<Integer> ft = new FutureTask<>(ctt);
    for (int i = 0; i < 100; i++) {
        System.out.println(Thread.currentThread().getName() + " 的循環變量i的值" + i);
        if (i == 20) {
            new Thread(ft, "有傳回值的線程").start();
        }
    }
    try {
        System.out.println("子線程的傳回值:" + ft.get());
    } catch (InterruptedException e) {
        log.error("e", e);
    } catch (ExecutionException e) {
        log.error("e", e);
    } catch (Exception e) {
        log.error("e", e);
    }
}
}      

存儲過程和for循環插入資料

#删除存儲過程

drop procedure callback

#設定存儲過程
 create procedure callback()
 begin
 declare num int;
 set num = 100;
 while
 num < 300 DO
 insert into test-demo(merchant_id, shop_name, remark)
 values(concat(num), concat(“shop_name”, num), concat(“remark”, num));
 set num = num + 1;
 end while;
 end;      

#執行存儲過程

call callback();

String字元串一般有什麼方法?

1、構造方法

String(String …)

String(char[] …)

String(char[] …,int …)

2、擷取長度

length()

3、擷取str在字元串對象中第一次出現的索引

indexOf(String str)

4、從start開始,到end結束截取字元串。包括start,不包括end

String substring(int start,int end)

5、判斷是否相同

equals(Object obj)

6、比較字元串的内容是否相同,忽略大小寫

equalsIgnoreCase(… …)

7、把字元串轉換為小寫字元串

toLowerCase()

8、把字元串轉換為大寫字元串

toUpperCase()

9、去除字元串兩端空格

trim()

面向對象怎麼了解?

1、面向對象概念

其本質是以建立模型展現出來的抽象思維過程和面向對象的方法

面向對象:将功能封裝進對象,強調具備了功能的對象

—》面向過程—》功能和行為

一切皆對象

打開關閉電腦是種行為,這過程是面向過程。

而電腦是對象,它有打開,上網,關閉的功能。

面向對象是一種思想,能讓複雜問題簡單化,程式員不需要了解具體的實作過程,隻需要指揮對象去實作功能。

好比把對象的功能封裝起來,我執行個體化對象,調用對象即可,它怎麼實作什麼功能讓它去實作。

2、三大特性擴開來講

繼承–》。。。。

多态–》。。。。

封裝–》。。。。

3、類與對象

人類是類。

小明是具體的人,是為對象。

4、擴充說面向對象其他特點

比如構造方法,static

資料庫排序?左連接配接 ?右連接配接?

1、資料庫排序

文法

select column_name,column_name from table_name order by column_name,column_name asc|desc

即select 列名 from 表名 order by 列名 asc|desc

用途

預設:升序

asc:指定列按升序排列

desc:指定列按降序排列

desc/asc :隻對後方的第一個列名有效,其他不受影響,仍是預設的升序。

2、

[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-3BynD1XP-1662873402593)(1)]

[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-EGBws14Q-1662873402596)(2)]

jQuery是什麼?

jQuery是前端重要的知識

jQuery 是一個 JavaScript 庫。

jQuery 極大地簡化了 JavaScript 程式設計。

簡單來說jQuery 就是把一些js方法封裝到庫裡面,應用jQuery可以使js的實作更加容易。

[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-2iELyqwG-1662873419644)(3)]

把jQuery庫引用到前端檔案中如index.jsp

<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>      

SpringBoot是什麼?它的優勢?