最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java中的常見幾種發(fā)送http請求實(shí)例

 更新時(shí)間:2024年11月08日 09:14:20   作者:北極熊不在北極  
在Java編程中,發(fā)送HTTP請求是一個(gè)常見需求,常用的方法有四種:HttpURLConnection、URLConnection、HttpClient以及Socket,其中,使用HttpClient方式時(shí),需要添加額外的庫支持

java常見幾種發(fā)送http請求實(shí)例

<span style="font-family: Arial, Helvetica, sans-serif;">import java.io.BufferedReader;</span>
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
 
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
 
/**
 * @Description:發(fā)送http請求幫助類
 * @author:liuyc
 * @time:2016年5月17日 下午3:25:32
 */
public class HttpClientHelper {
	/**
	 * @Description:使用HttpURLConnection發(fā)送post請求
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:26:07
	 */
	public static String sendPost(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> e : params.entrySet()) {
				sbParams.append(e.getKey());
				sbParams.append("=");
				sbParams.append(e.getValue());
				sbParams.append("&");
			}
		}
		HttpURLConnection con = null;
		OutputStreamWriter osw = null;
		BufferedReader br = null;
		// 發(fā)送請求
		try {
			URL url = new URL(urlParam);
			con = (HttpURLConnection) url.openConnection();
			con.setRequestMethod("POST");
			con.setDoOutput(true);
			con.setDoInput(true);
			con.setUseCaches(false);
			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			if (sbParams != null && sbParams.length() > 0) {
				osw = new OutputStreamWriter(con.getOutputStream(), charset);
				osw.write(sbParams.substring(0, sbParams.length() - 1));
				osw.flush();
			}
			// 讀取返回內(nèi)容
			resultBuffer = new StringBuffer();
			int contentLength = Integer.parseInt(con.getHeaderField("Content-Length"));
			if (contentLength > 0) {
				br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
				String temp;
				while ((temp = br.readLine()) != null) {
					resultBuffer.append(temp);
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (osw != null) {
				try {
					osw.close();
				} catch (IOException e) {
					osw = null;
					throw new RuntimeException(e);
				} finally {
					if (con != null) {
						con.disconnect();
						con = null;
					}
				}
			}
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				} finally {
					if (con != null) {
						con.disconnect();
						con = null;
					}
				}
			}
		}
 
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:使用URLConnection發(fā)送post
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:26:52
	 */
	public static String sendPost2(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> e : params.entrySet()) {
				sbParams.append(e.getKey());
				sbParams.append("=");
				sbParams.append(e.getValue());
				sbParams.append("&");
			}
		}
		URLConnection con = null;
		OutputStreamWriter osw = null;
		BufferedReader br = null;
		try {
			URL realUrl = new URL(urlParam);
			// 打開和URL之間的連接
			con = realUrl.openConnection();
			// 設(shè)置通用的請求屬性
			con.setRequestProperty("accept", "*/*");
			con.setRequestProperty("connection", "Keep-Alive");
			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			con.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			// 發(fā)送POST請求必須設(shè)置如下兩行
			con.setDoOutput(true);
			con.setDoInput(true);
			// 獲取URLConnection對象對應(yīng)的輸出流
			osw = new OutputStreamWriter(con.getOutputStream(), charset);
			if (sbParams != null && sbParams.length() > 0) {
				// 發(fā)送請求參數(shù)
				osw.write(sbParams.substring(0, sbParams.length() - 1));
				// flush輸出流的緩沖
				osw.flush();
			}
			// 定義BufferedReader輸入流來讀取URL的響應(yīng)
			resultBuffer = new StringBuffer();
			int contentLength = Integer.parseInt(con.getHeaderField("Content-Length"));
			if (contentLength > 0) {
				br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
				String temp;
				while ((temp = br.readLine()) != null) {
					resultBuffer.append(temp);
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (osw != null) {
				try {
					osw.close();
				} catch (IOException e) {
					osw = null;
					throw new RuntimeException(e);
				}
			}
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				}
			}
		}
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:發(fā)送get請求保存下載文件
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:27:29
	 */
	public static void sendGetAndSaveFile(String urlParam, Map<String, Object> params, String fileSavePath) {
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				sbParams.append(entry.getValue());
				sbParams.append("&");
			}
		}
		HttpURLConnection con = null;
		BufferedReader br = null;
		FileOutputStream os = null;
		try {
			URL url = null;
			if (sbParams != null && sbParams.length() > 0) {
				url = new URL(urlParam + "?" + sbParams.substring(0, sbParams.length() - 1));
			} else {
				url = new URL(urlParam);
			}
			con = (HttpURLConnection) url.openConnection();
			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			con.connect();
			InputStream is = con.getInputStream();
			os = new FileOutputStream(fileSavePath);
			byte buf[] = new byte[1024];
			int count = 0;
			while ((count = is.read(buf)) != -1) {
				os.write(buf, 0, count);
			}
			os.flush();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (os != null) {
				try {
					os.close();
				} catch (IOException e) {
					os = null;
					throw new RuntimeException(e);
				} finally {
					if (con != null) {
						con.disconnect();
						con = null;
					}
				}
			}
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				} finally {
					if (con != null) {
						con.disconnect();
						con = null;
					}
				}
			}
		}
	}
 
	/**
	 * @Description:使用HttpURLConnection發(fā)送get請求
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:27:29
	 */
	public static String sendGet(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				sbParams.append(entry.getValue());
				sbParams.append("&");
			}
		}
		HttpURLConnection con = null;
		BufferedReader br = null;
		try {
			URL url = null;
			if (sbParams != null && sbParams.length() > 0) {
				url = new URL(urlParam + "?" + sbParams.substring(0, sbParams.length() - 1));
			} else {
				url = new URL(urlParam);
			}
			con = (HttpURLConnection) url.openConnection();
			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			con.connect();
			resultBuffer = new StringBuffer();
			br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
			String temp;
			while ((temp = br.readLine()) != null) {
				resultBuffer.append(temp);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				} finally {
					if (con != null) {
						con.disconnect();
						con = null;
					}
				}
			}
		}
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:使用URLConnection發(fā)送get請求
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:27:58
	 */
	public static String sendGet2(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				sbParams.append(entry.getValue());
				sbParams.append("&");
			}
		}
		BufferedReader br = null;
		try {
			URL url = null;
			if (sbParams != null && sbParams.length() > 0) {
				url = new URL(urlParam + "?" + sbParams.substring(0, sbParams.length() - 1));
			} else {
				url = new URL(urlParam);
			}
			URLConnection con = url.openConnection();
			// 設(shè)置請求屬性
			con.setRequestProperty("accept", "*/*");
			con.setRequestProperty("connection", "Keep-Alive");
			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			con.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			// 建立連接
			con.connect();
			resultBuffer = new StringBuffer();
			br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
			String temp;
			while ((temp = br.readLine()) != null) {
				resultBuffer.append(temp);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				}
			}
		}
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:使用HttpClient發(fā)送post請求
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:28:23
	 */
	public static String httpClientPost(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		HttpClient client = new DefaultHttpClient();
		HttpPost httpPost = new HttpPost(urlParam);
		// 構(gòu)建請求參數(shù)
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		Iterator<Entry<String, Object>> iterator = params.entrySet().iterator();
		while (iterator.hasNext()) {
			Entry<String, Object> elem = iterator.next();
			list.add(new BasicNameValuePair(elem.getKey(), String.valueOf(elem.getValue())));
		}
		BufferedReader br = null;
		try {
			if (list.size() > 0) {
				UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, charset);
				httpPost.setEntity(entity);
			}
			HttpResponse response = client.execute(httpPost);
			// 讀取服務(wù)器響應(yīng)數(shù)據(jù)
			resultBuffer = new StringBuffer();
			br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			String temp;
			while ((temp = br.readLine()) != null) {
				resultBuffer.append(temp);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				}
			}
		}
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:使用HttpClient發(fā)送get請求
	 * @author:liuyc
	 * @time:2016年5月17日 下午3:28:56
	 */
	public static String httpClientGet(String urlParam, Map<String, Object> params, String charset) {
		StringBuffer resultBuffer = null;
		HttpClient client = new DefaultHttpClient();
		BufferedReader br = null;
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				try {
					sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), charset));
				} catch (UnsupportedEncodingException e) {
					throw new RuntimeException(e);
				}
				sbParams.append("&");
			}
		}
		if (sbParams != null && sbParams.length() > 0) {
			urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
		}
		HttpGet httpGet = new HttpGet(urlParam);
		try {
			HttpResponse response = client.execute(httpGet);
			// 讀取服務(wù)器響應(yīng)數(shù)據(jù)
			br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			String temp;
			resultBuffer = new StringBuffer();
			while ((temp = br.readLine()) != null) {
				resultBuffer.append(temp);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					br = null;
					throw new RuntimeException(e);
				}
			}
		}
		return resultBuffer.toString();
	}
 
	/**
	 * @Description:使用socket發(fā)送post請求
	 * @author:liuyc
	 * @time:2016年5月18日 上午9:26:22
	 */
	public static String sendSocketPost(String urlParam, Map<String, Object> params, String charset) {
		String result = "";
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				sbParams.append(entry.getValue());
				sbParams.append("&");
			}
		}
		Socket socket = null;
		OutputStreamWriter osw = null;
		InputStream is = null;
		try {
			URL url = new URL(urlParam);
			String host = url.getHost();
			int port = url.getPort();
			if (-1 == port) {
				port = 80;
			}
			String path = url.getPath();
			socket = new Socket(host, port);
			StringBuffer sb = new StringBuffer();
			sb.append("POST " + path + " HTTP/1.1\r\n");
			sb.append("Host: " + host + "\r\n");
			sb.append("Connection: Keep-Alive\r\n");
			sb.append("Content-Type: application/x-www-form-urlencoded; charset=utf-8 \r\n");
			sb.append("Content-Length: ").append(sb.toString().getBytes().length).append("\r\n");
			// 這里一個(gè)回車換行,表示消息頭寫完,不然服務(wù)器會(huì)繼續(xù)等待
			sb.append("\r\n");
			if (sbParams != null && sbParams.length() > 0) {
				sb.append(sbParams.substring(0, sbParams.length() - 1));
			}
			osw = new OutputStreamWriter(socket.getOutputStream());
			osw.write(sb.toString());
			osw.flush();
			is = socket.getInputStream();
			String line = null;
			// 服務(wù)器響應(yīng)體數(shù)據(jù)長度
			int contentLength = 0;
			// 讀取http響應(yīng)頭部信息
			do {
				line = readLine(is, 0, charset);
				if (line.startsWith("Content-Length")) {
					// 拿到響應(yīng)體內(nèi)容長度
					contentLength = Integer.parseInt(line.split(":")[1].trim());
				}
				// 如果遇到了一個(gè)單獨(dú)的回車換行,則表示請求頭結(jié)束
			} while (!line.equals("\r\n"));
			// 讀取出響應(yīng)體數(shù)據(jù)(就是你要的數(shù)據(jù))
			result = readLine(is, contentLength, charset);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (osw != null) {
				try {
					osw.close();
				} catch (IOException e) {
					osw = null;
					throw new RuntimeException(e);
				} finally {
					if (socket != null) {
						try {
							socket.close();
						} catch (IOException e) {
							socket = null;
							throw new RuntimeException(e);
						}
					}
				}
			}
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					is = null;
					throw new RuntimeException(e);
				} finally {
					if (socket != null) {
						try {
							socket.close();
						} catch (IOException e) {
							socket = null;
							throw new RuntimeException(e);
						}
					}
				}
			}
		}
		return result;
	}
 
	/**
	 * @Description:使用socket發(fā)送get請求
	 * @author:liuyc
	 * @time:2016年5月18日 上午9:27:18
	 */
	public static String sendSocketGet(String urlParam, Map<String, Object> params, String charset) {
		String result = "";
		// 構(gòu)建請求參數(shù)
		StringBuffer sbParams = new StringBuffer();
		if (params != null && params.size() > 0) {
			for (Entry<String, Object> entry : params.entrySet()) {
				sbParams.append(entry.getKey());
				sbParams.append("=");
				sbParams.append(entry.getValue());
				sbParams.append("&");
			}
		}
		Socket socket = null;
		OutputStreamWriter osw = null;
		InputStream is = null;
		try {
			URL url = new URL(urlParam);
			String host = url.getHost();
			int port = url.getPort();
			if (-1 == port) {
				port = 80;
			}
			String path = url.getPath();
			socket = new Socket(host, port);
			StringBuffer sb = new StringBuffer();
			sb.append("GET " + path + " HTTP/1.1\r\n");
			sb.append("Host: " + host + "\r\n");
			sb.append("Connection: Keep-Alive\r\n");
			sb.append("Content-Type: application/x-www-form-urlencoded; charset=utf-8 \r\n");
			sb.append("Content-Length: ").append(sb.toString().getBytes().length).append("\r\n");
			// 這里一個(gè)回車換行,表示消息頭寫完,不然服務(wù)器會(huì)繼續(xù)等待
			sb.append("\r\n");
			if (sbParams != null && sbParams.length() > 0) {
				sb.append(sbParams.substring(0, sbParams.length() - 1));
			}
			osw = new OutputStreamWriter(socket.getOutputStream());
			osw.write(sb.toString());
			osw.flush();
			is = socket.getInputStream();
			String line = null;
			// 服務(wù)器響應(yīng)體數(shù)據(jù)長度
			int contentLength = 0;
			// 讀取http響應(yīng)頭部信息
			do {
				line = readLine(is, 0, charset);
				if (line.startsWith("Content-Length")) {
					// 拿到響應(yīng)體內(nèi)容長度
					contentLength = Integer.parseInt(line.split(":")[1].trim());
				}
				// 如果遇到了一個(gè)單獨(dú)的回車換行,則表示請求頭結(jié)束
			} while (!line.equals("\r\n"));
			// 讀取出響應(yīng)體數(shù)據(jù)(就是你要的數(shù)據(jù))
			result = readLine(is, contentLength, charset);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (osw != null) {
				try {
					osw.close();
				} catch (IOException e) {
					osw = null;
					throw new RuntimeException(e);
				} finally {
					if (socket != null) {
						try {
							socket.close();
						} catch (IOException e) {
							socket = null;
							throw new RuntimeException(e);
						}
					}
				}
			}
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					is = null;
					throw new RuntimeException(e);
				} finally {
					if (socket != null) {
						try {
							socket.close();
						} catch (IOException e) {
							socket = null;
							throw new RuntimeException(e);
						}
					}
				}
			}
		}
		return result;
	}
 
	/**
	 * @Description:讀取一行數(shù)據(jù),contentLe內(nèi)容長度為0時(shí),讀取響應(yīng)頭信息,不為0時(shí)讀正文
	 * @time:2016年5月17日 下午6:11:07
	 */
	private static String readLine(InputStream is, int contentLength, String charset) throws IOException {
		List<Byte> lineByte = new ArrayList<Byte>();
		byte tempByte;
		int cumsum = 0;
		if (contentLength != 0) {
			do {
				tempByte = (byte) is.read();
				lineByte.add(Byte.valueOf(tempByte));
				cumsum++;
			} while (cumsum < contentLength);// cumsum等于contentLength表示已讀完
		} else {
			do {
				tempByte = (byte) is.read();
				lineByte.add(Byte.valueOf(tempByte));
			} while (tempByte != 10);// 換行符的ascii碼值為10
		}
 
		byte[] resutlBytes = new byte[lineByte.size()];
		for (int i = 0; i < lineByte.size(); i++) {
			resutlBytes[i] = (lineByte.get(i)).byteValue();
		}
		return new String(resutlBytes, charset);
	}
	
}

上面4種分別可發(fā)送get和post請求的方法

  • 第1種:HttpURLConnection、
  • 第2種:URLConnection、
  • 第3種:HttpClient、
  • 第4種:Socket,朋友們要注意的是,使用第3種HttpClient時(shí)需要依賴于三個(gè)jar包,分別是:apache-httpcomponents-httpclient.jar、commons-logging-1.0.4.jar、httpcore-4.1.1.jar。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java中的volatile關(guān)鍵字多方面解析

    Java中的volatile關(guān)鍵字多方面解析

    volatile用于保證多線程變量可見性與禁止重排序,適用于狀態(tài)標(biāo)志、單例模式等場景,但不保證原子性,相較synchronized更輕量,但需謹(jǐn)慎使用以避免復(fù)合操作問題,本文給大家解析Java中的volatile關(guān)鍵字,感興趣的朋友一起看看吧
    2025-08-08
  • java在網(wǎng)頁上面抓取郵件地址的方法

    java在網(wǎng)頁上面抓取郵件地址的方法

    這篇文章主要介紹了java在網(wǎng)頁上面抓取郵件地址的方法,是比較典型的Java正則匹配應(yīng)用實(shí)例,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-11-11
  • 詳解Java設(shè)計(jì)模式編程中的策略模式

    詳解Java設(shè)計(jì)模式編程中的策略模式

    這篇文章主要介紹了詳解Java設(shè)計(jì)模式編程中的策略模式,策略模式強(qiáng)調(diào)對對象的封裝使用,比如文中舉的錦囊妙計(jì)的例子便很生動(dòng),需要的朋友可以參考下
    2016-02-02
  • Java基礎(chǔ)知識(shí)之Java語言概述

    Java基礎(chǔ)知識(shí)之Java語言概述

    這篇文章主要介紹了Java基礎(chǔ)知識(shí)之Java語言概述,本文介紹了Java語言相關(guān)的基礎(chǔ)知識(shí)、歷史介紹、主要應(yīng)用方向等內(nèi)容,需要的朋友可以參考下
    2015-03-03
  • 源碼解析JDK 1.8 中的 Map.merge()

    源碼解析JDK 1.8 中的 Map.merge()

    這篇文章主要介紹了JDK 1.8 之 Map.merge()的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-10-10
  • java內(nèi)存模型jvm虛擬機(jī)簡要分析

    java內(nèi)存模型jvm虛擬機(jī)簡要分析

    Java 內(nèi)存模型的主要目的是定義程序中各種變量的訪問規(guī)則, 關(guān)注在虛擬機(jī)中把變量值存儲(chǔ)到內(nèi)存和從內(nèi)存中取出變量值這樣的底層細(xì)節(jié)
    2021-09-09
  • Java 8 Stream操作類型及peek示例解析

    Java 8 Stream操作類型及peek示例解析

    這篇文章主要介紹了Java 8 Stream操作類型及peek示例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • java中對象的比較equal、Comparble、Comparator的區(qū)別

    java中對象的比較equal、Comparble、Comparator的區(qū)別

    本文主要介紹了java中對象的比較equal、Comparble、Comparator的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • SpringBoot應(yīng)用內(nèi)存占用分析與優(yōu)化指南

    SpringBoot應(yīng)用內(nèi)存占用分析與優(yōu)化指南

    本文詳細(xì)分析了SpringBoot應(yīng)用內(nèi)存占用過高的原因,主要包括JVM堆內(nèi)存、元空間、線程棧內(nèi)存和直接內(nèi)存等,通過優(yōu)化Tomcat線程池配置、調(diào)整JVM參數(shù),并結(jié)合監(jiān)控機(jī)制,可以有效降低應(yīng)用內(nèi)存占用,提高性能和穩(wěn)定性,需要的朋友可以參考下
    2026-03-03
  • 查看SpringBoot和JDK版本對應(yīng)關(guān)系的方法

    查看SpringBoot和JDK版本對應(yīng)關(guān)系的方法

    在進(jìn)行一些自主學(xué)習(xí)的時(shí)候,發(fā)現(xiàn)使用maven方式創(chuàng)建的SpringBoot項(xiàng)目啟動(dòng)失敗,最終發(fā)現(xiàn)是SpringBoot版本和JDK版本不對應(yīng)導(dǎo)致的,所以本文就給大家介紹了如何查看SpringBoot和JDK版本的對應(yīng)關(guān)系,需要的朋友可以參考下
    2024-03-03

最新評(píng)論

赤壁市| 德兴市| 霍林郭勒市| 彰武县| 乐陵市| 中宁县| 永和县| 连山| 绥江县| 大足县| 于田县| 浙江省| 静海县| 邯郸县| 临桂县| 广安市| 无为县| 阿克苏市| 天水市| 彰化县| 阿荣旗| 井研县| 佳木斯市| 卓尼县| 双桥区| 伊吾县| 峡江县| 宜君县| 封丘县| 牡丹江市| 泸溪县| 梁河县| 土默特右旗| 元江| 永丰县| 花垣县| SHOW| 北票市| 湖州市| 海晏县| 宁强县|