ThreadLocal은 jdk1.2부터 있었다고 하는데, 그 동안 이런게 있는지 잘 몰랐다.

 

용도는 2가지인데

1. Thread별로 싱글턴 같은 global(local)변수를 생성/관리되므로, Thread별로 분리된 변수를 사용가능.

=> REF : per-thread Singleton.

 
    ==> synchronized없이도 Lock이 자동으로 방지 될 걸로 예상 됨..(이건 좀 토론이 필요함)

 

 

1.1. 하나의 Thread안에서 여러 class가 공용메모리 처럼 사용가능. (왜냐하면 Thread안에서 global이니깐)

 

관련사이트1 , 관련사이트2

 

 

 

 File f = File.createTempFile("aaa",".tmp")  도 유사한 성격으로 동시 접근을 피할 수 있다.

 write다한 후에 보통 f.setReadOnly();

==> 똑같은 파일명으로 만들어도 알아서 숫자가 붙는 방식임. 따라서 .deleteOnExit() 설정을 꼭 해주는 게 좋다.

Posted by yongary
,

EL과 JSTL

Spring 2015. 8. 7. 14:48

참고사이트:  http://egloos.zum.com/slog2/v/3581446   https://docs.oracle.com/javaee/6/tutorial/doc/bnahq.html 

 

 

EL (expression language) -> JSP2부터 기본 지원

JSTL (JavaServer Pages Standard Tag Library ) -> c tag를 가장 많이 사용.

 

앞부분에 taglib 디렉티브로 사용함을 표시한다.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  // c:tag사용.

 

<EL>

${param.name} => request.getParameter("name");
${member} => request.getAttribute("member");

 

${member.name} => Member m = (Member)request.getAttribute("member");
m.getName();
${list["0"]} => List list = (List)request.getAttribute("list");
list.get(0);

 <JSTL>

<c:forEach items="${list}" var="listItem" >

<td>${listItem.title}</td>

</c:forEach> 

 

Posted by yongary
,

javascript관련 질문들:

 

javascript에는 function statement와 function expression이 존재한다.

비슷하지만 약간의 차이가 난다.

 

<Function>

  - function expression: var x = function fname(){}   (fname is optional) 

 => 이걸로 싱글턴 만들수 있다. class만들고 싱클턴 만드는 거 보다 less expensive.

  - function statement:   function fname(){}

 

<기타>

  - javascript 에 {blocks}  는  scope을 가지지 않는다. 

 

<슈도 파라미터 2가지>

  - arguments : parameter와 밀접한 관계가 있으므로, read-only로 사용하는 게 좋다.

       일종의 array로 최근(ES5)에 .reduce 등이 소개되었다. 
         arguments.length

         arguments[i]

 

  - this : function 내에서 멤버변수를위한 public 키워드처럼 동작하기도 하며, (이건 아래2번)

1. reference to the object of invocation

2. allows to know the concerned Object

3. allows single function object to service many functions ?

4. key to prototype inheritance

 

Function.prototype.bind를 통해 this를 강제로 할당 할 수 있다.

 


<prototype이란>

All JavaScript objects inherit the properties and methods from their prototype.

Allows you to add properties and methods to an object 

we can inherit using prototype. and by overriding construct(). => prototype is copied.




<function관련 Form종류들>

  - New폼:      new functionObject() 

  - function폼: functionObject(arg) 이 경우, var that = this; 많이 사용. inner function이 outer를 접근하기 위해서..
                     (왜냐면 자체 this가 있기 때문)

  - method폼:  functionObject(arg).method()

  - apply폼:    apply()  form  ,   유사한것으로 call도 있는데, apply는 (this,array)  call은 (this, a,b,c : each object of array)가 전달된다.

 

 

this 참고사이트:  http://mobicon.tistory.com/189  

유투브:   15분-this,  30분-closure  (English)








Posted by yongary
,

hoisting, strict mode

javascript 2015. 8. 4. 19:19

javascript에서 hoisting이란 

 변수나 함수를 var 로 선언하기 전에도 사용할 수 있다는 의미이다.  참고사이트

(global함수의 경우는 어디서나 사용할 수 있으므로 hoisting이 아니다.)


참고사이트:영어

In JavaScript,  a variable can be used before it has been declared.


hoisting이 왜 중요한가?

==> 크드가 잘 돌아가더라도 hoisting이 동작한 것일 수 있기 때문에, hoisting을 알아두는 것이 각종버그를 방지할 수 있다.


strict mode : "use strict";  를 사용하면  hoisting을 방지할 수 있다. (꼭 선언 후 사용하는 모드)  w3schools_js



Posted by yongary
,

some JAVA keywords

java core 2015. 8. 2. 22:49

finalize(): GC calls when Instance is garbage collected. which has no reference.    참고사이트:


hashCode();  when making equals method of Object. we must consider this method().


final: (method or class) will not be inheritted.





Posted by yongary
,

(팁: 크롬으로 javascript 개발시 F12 키가 debug모드이다 :   메뉴엔 Ctrl-Shft-J)



JavaScript의 객체 상속도를 잘 나타낸 그림은 다음과 같다.  참고사이트:devbox


DOM구조에서 거의 모든 object들이 Node를 상속받아서 만들어 졌다고 보면된다.

그런데 개발시에는 node API를 쓰면 필요없는 tag등이 한번씩 나오는 경우가 있어서

위한 children() 함수를 더 많이 쓰게 된다. 


<많이 쓰는 코드>

    document.getElementById('aa').children  -> HTMLCollections 를 리턴함.

    

    (document.getElementByxxx부터 해서,  Element를 특히 많이 씀)

    document.getElementById('aa').children.item(i)  --> Element 리턴.

jquery의 경우는 : $('#aa')[0].childNodes[0].nodeValue;

  $($('h1').contents().get(0)).text(); //.get(0)=[0]

  $('h1').contents().each(function() {
          
if(this.nodeType == 3) { }


    removeChild(e) 

    appendChild(e)

    document.createElement('div')





Posted by yongary
,

UML & GoF pattern

IT 2015. 7. 29. 22:53

<UML>  Reference Site:


 Inheritance:       ㅡㅡㅡㅡㅡD        


 Interface:          - - - - - - D


 association(has):   A  ㅡㅡㅡㅡㅡ>     B               class A { member B}   

                                  Leg  <.>----->  필수.

           Flea <>------>



 dependency:             A  - - - - - >     B                 class A uses B temporary.




<Gof Pattern> Reference SIte

Creational Pattern:  Singleton, (Abstract)Factory, Builder, Prototype

Structral Pattern: Adapter, Decorator, Bridge, Proxy

Behavior Pattern: Command, Iterator, Visitor, Observer, Chain of Responsibility



Posted by yongary
,

OSGi for Java

java core 2015. 7. 29. 18:48

OSGI (Open Services Gateway Initiative)   REF-SITE:


- Originally targeted embedded devcies & home service GWs.

- Bundle based Fluent Life-Cycle framework.  (Bundle=jar+alpha)

   (life-cycle Layer can dynamically install/remove/start/stop bundles)

- JavaObject based SOA  


ex)  Eclipse Equinox PDE (Plug-in Development Environment)

     Apache Felix.  Reference-Site


Posted by yongary
,

참고사이트: Javascript 재입문


parseInt( "11", 2) = 3

NaN : Not a number    

Infinity : 무한대   1/0 = Infinity


1==true : true   (type이 오토케스팅 됨)

1===true: false  (===: type 강제변환 방지: type까지 비교함. )

 

var names;   //names == undefined임.

  이 때, !names == !undefined  //둘다 true임. 

 

setTimeout(func, 100) //0.1초 후 실행.

setInterval(func,100)  //0.1초씩 반복


for (var i in a)  //a[i]사용가능,   var a=["dog","cat","chicken"]

 

<주의>

var z = 0.1 + 0.2;  //z=0.300....4   모든 수가 64bit float이라 계산에 오류발생 가능.

javascript는 head나 body에 모두 사용가능하다.

==의 반대말은 !=  ( <>아님)

javascript는 당근 case Sensitive하다.

 

 

<JS object>

var person = {
    firstName: "John",
    lastName : "Doe",
    id       : 5566,
    fullName : function() {
       return this.firstName + " " + this.lastName;
    }
};  ==> prototype기반 function보단 사용용도가 약하지만, JSON은 큰 장점.

 

<array>

[1,2].concat([2,3]);  //Array.concat => [1,2,2,3]  혹은 arrA.concat(arrA)

[2,3,4].join()   // toString.. "2,3,4"

 

 

<기타>

navigator.userAgent;

navigator.appName ;  브라우저 name

window.btoa("abc") //=> base64 encoding.

 

<< My experience >>

new window['Pattern'+ i]()           //= new Pattern1 ~ new Pattern6

apply(obj, [a,b])  or   call(obj, a,b)   // 0bj->this, (a,b)   this chapter 참조.  

Posted by yongary
,





Curran의 20번 exam:

- $http 서비스를 이용해 json을 웹으로 가져오기.

<html ng-app="countryApp">

<head>

<meta charset="utf-8">
<title>Angular.js Example</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http){

$http.get('countries.json').success(function(data) {

$scope.countries = data;
});
});
</script>
</head>
<body ng-controller="CountryCtrl">
<table>
<tr>
<th>Country</th>
<th>Population</th>
</tr>
<tr ng-repeat="country in countries">
<td>{{country.name}}</td>
<td>{{country.population}}</td>
</tr>
</table>
</body>
</html>


Posted by yongary
,