즐겁게/anything 4

파일명이 중복일때 숫자를 붙여서 새로운 파일명 만들기

파일을 복사할때 동일한 파일이 존재하는 경우 덮어쓰지 않도록 하려면 이름에 숫자를 붙여서 만들어야 하는 경우가 종종 발생함 fileName.txt, fileName(1).txt, fileName(2).txt ... 와 같이 (숫자)를 붙여서 새로운 파일명을 생성하여 처리 public static String getNewFileName(String toFilePath) { String dest = toFilePath; String dot = "."; if (StringUtils.isEmpty(toFilePath)) return dest; if(!Files.exists(Paths.get(dest))) return dest; try { File f = new File(toFilePath); String fil..

즐겁게/anything 2022.12.16

ExpiringMap(net.jodah) 지정한 시간 동안만 저장되고 자동 삭제

지정한 시간동안 지정한 최대 개수만큼만 저장했다가 자동으로 삭제되는 맵, 캐시와 유사 : A high performance, low-overhead, zero dependency, thread-safe ConcurrentMap implementation that expires entries. 참조: https://github.com/jhalterman/expiringmap GitHub - jhalterman/expiringmap: A high performance thread-safe map that expires entries A high performance thread-safe map that expires entries - GitHub - jhalterman/expiringmap: A high p..

즐겁게/anything 2022.11.02

JAVA 메모리 사용량 확인

현재 실행중인 Java application의 메모리 사용량을 확인해 볼 수 있다.// JVM이 허용하는 최대 힙 메모리 크기, -Xmx// long maxMem = Runtime.getRuntime().maxMemory()/1024/1024;// 아래 내용(Runtime.getRuntime().maxMemory())을 보완하기위해 수정된 소스long maxMem = 0L;MemoryMXBean m = ManagementFactory.getMemoryMXBean();for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) { if(mp.getName().indexOf("Tenured") > -1){ maxMem += mp..

즐겁게/anything 2022.10.27

JavaMail API를 이용한 메일 발송

javamail api를 이용하여 메일을 발송할 때 1) SMTP 아이디 인증을 통한 방식 또는 2) 발송서버의 아이피를 메일서버에 릴레이 허용 아이피로 등록하여 처리가 가능 public void sendMail(){ String smtpServer = "메일서버_아이피"; String smtpPort = "발송포트(25)"; // SMTP 인증방식을 이용하는 경우 // String smtpUserid = "SMTP 인증 계정"; // String smtpPwd = "SMTP 인증 비밀번호"; Properties prop = new Properties(); // 메일서버 주소 prop.put("mail.smtp.host", smtpServer); // 포트(기본 25) prop.put("mail.smtp..

즐겁게/anything 2022.10.23
반응형