분류 전체보기
-
자바 - thread(3) 실행제어 메서드 예제언어/JAVA 2023. 3. 21. 15:42
sleep(long millis) :일정시간동안 쓰레드를 멈추게한다. -Thread 클래스의 static 메서드로 항상 현재 쓰레드에만 적용된다. (sleep을 사용한 쓰레드) - sleep()에 의해 일시정지가 상태가 된 쓰레드는 지정된 시간이 다 지나거나 interrupt()가 호출되면(InterruptedException이 발생) 실행대기 상태가 된다. (항상 try-catch필요) 주로 sleep을 포함하는 메서드를 만들어서 사용한다. void delay(long millis){ //sleep()에 대한 try-catch } public class ThreadEX1 { public static void main(String[] args) throws Exception{ ThreadEx2 th1 =..
-
자바 -thread(2) [5~8]언어/JAVA 2023. 3. 20. 16:17
1.쓰레드의 우선순위 쓰레드는 우선순위(priority)라는 속성을 가지고 있다. 우선순위에 따라 쓰레드가 얻는 실행시간이 달라진다. 우선순위가 높으면, 더 많은 작업시간을 할당할 수 있다. -void setPriority(int newPriority) -쓰레드의 우선순위를 지정한 값으로 변경 (기본값 5) -int getPriority() -스레드의 우선순위를 반환한다. *JVM은 우선순위를 1~10까지 두고있고, winOS는 32단계의 우선순위를 가지고 있다. 쓰레드는 결론적으로 os의 스케쥴러에 의해 영향을 받으므로, 우리가 jvm을 통해 설정하는 우선순위는 희망사항일 뿐 강제될 순 없다. public class ThreadEX1 { //static long startTime =0; public s..
-
자바 - thread(1) 기본특성 (1~4)언어/JAVA 2023. 3. 20. 12:49
1. 프로세스와 쓰레드 프로세스: 실행 중인 프로그램이다. 프로그램을 실행하면 OS로부터 필요한 자원을 할당받아 프로세스가 된다. -프로세스는 데이터 메모리 등의 자원과 쓰레드로 구성되어 있다. - 모든 프로세스는 하나 이상의 쓰레드가 존재하며, 둘 이상의 쓰레드를 가진 프로세스를 멀티쓰레드 프로세스라 한다. 쓰레드 : 프로세스 내의 자원을 이용해서 실제 작업을 수행 (프로세스의 실행 단위) - 위와 같이 하나의 프로세스에 자원과 쓰레드가 있다. 쓰레드 각각은 내부에 스택과 고유한 프로그램 카운터 값을 가지고 있으며, 프로세스 내에 자원들을 공유하며 각자의 작업을 처리한다. **이때 각 쓰레드에 스택 메모리를 할당하는 이유는 스레드마다 독립적으로 함수를 호출하고, 자원을 사용하는 등 독립적 작업을 처리하..
-
자바 - Generics언어/JAVA 2023. 3. 16. 12:09
1. Generics란? -데이터타입의 일반화를 의미 (generalize) -다양한 타입의 객체를 다루는 메서드나, 컬렉션 클래스에 타입체크 기능 -컴파일 시 이러한 타입 체크를 통해 타입의 안정성을 제공하고, 타입체크와 형변환 생략으로 코드가 간결해진다. 간단하게 객체의 타입을 미리 명시하므로써 형변환의 번거로움을 줄이고, 잘못된 타입의 기입을 컴파일 과정에서 잡아내어 오류를 줄여준다. *generics가 도입되기 이전인 JDK 1.5이전에는 여러타입을 매개변수로 받거나, 반환할 때 Object를 사용했다. ->이 경우에 Object타입을 다시 형변환해야하는 번거로움이 있고, 이 과정에서 오류 발생 가능성이 있다. generics는 이를 보완해준다. * List처럼 인스턴스 필드에 타입 변수 객체 가..
-
배열 기반 List (C and java)자료구조와 알고리즘/자료구조 2023. 3. 10. 16:46
자료구조의 첫 걸음인 배열기반 리스트를 구현해 보았다. 추상자료형(ADT) -구현하고자 하는 자료구조에 대해 구체적인 기능의 완성과정을 언급하지 않고, 순수하게 기능이 무엇인지를 나열 한 것을 가리켜 추상자료형 ADT라고 한다. 특정 자료형의 내부 구현은 정확하게 알지 못해도 활용할 수 있도록 명시하는 작업이라고 생각해 볼 수 있다. (마치 자바에서 인터페이스 혹은 추상 클래스를 정의하는 것과 비슷한 느낌이다.) 자료구조를 공부할 때 1. ADT를 정의하고 2. ADT를 근거로 자료구조를 활용하는 함수를 정의하고 3. ADT를 근거로 구현하는 과정 위 3단계 과정이 필요하다. 배열을 이용한 LIST 자료형의 구현 리스트는 간단하게 말해서 저장순서를 유지하고, 중복을 허용하여 자료를 저장하는 구조이다. 1..
-
자바 콘솔 -bulls and cows 게임미니 2023. 3. 10. 13:57
class Number_exceed_Exception extends Exception { String msg; Number_exceed_Exception(int a, int b) { this.msg = "Error: it's not possible to generate a code with " + "a length of " + a + " with " + b + " unique symbols."; } Number_exceed_Exception() { } } class Maxinum_number_Exception extends Number_exceed_Exception { Maxinum_number_Exception() { super.msg = "Error: maximum number of possible ..
-
자바 콘솔 -커피머신미니 2023. 3. 9. 11:36
import java.util.Scanner; public class CoffeeMachine { public static void main(String[] args) { CoffeeMachine a = CoffeeMachine.getCoffeeMachine(); a.On(); } private int[] igre = new int[5]; private enum selection { ESPRESSO(new int[]{250,0,16,4}), LATTE(new int[]{350,75,20,7}), CAPPUCCINO(new int[]{200,100,12,6}); private int[] ing = new int[4]; private selection(int[] re){ this.ing = re; } pub..
-
스프링 - 간단 용어들 정리Web/Spring 2023. 3. 5. 21:30
-스프링을 배우며 등장하는 용어들 조금씩 정리 JSP(java Server Pages) HTML코드에 JAVA코드를 넣어서 동적 웹페이지를 생성하는 웹 어플리케이션 도구 자바 언어를 기반으로 하는 Server Side 스크립트 언어이다. WAS에서 jsp로 작성된 프로그램은 서버로 요청시 서블릿 파일로 변환된다. ->jsp태그 분해 추출 -> 순수 html로 변환 Servlet 웹 페이지를 동적으로 생성하는 서버 측 프로그램을 의미 웹 서버의 성능을 향상하기 위해 사용되는 자바 클래스의 일종이다. 정적 페이지 뿐 아니라 동적 페이지를 만들기 위해 등장 서블릿은 WAS(Web Application Server)의 서블릿 컨테이너 안에서 동작한다. WAS (Web Application Server) 웹서버 ..