'Code Muri'에 해당되는 글 690건

  1. 2015.05.12 Exception Handling in Spring MVC
  2. 2015.04.15 Spring Security JSP Tag Libraries
  3. 2015.04.15 Functional Testing and Non-Functional Testing
  4. 2015.04.07 Spring MVC and HDIV example application and Debugging
  5. 2015.03.17 Responsive Web
  6. 2015.02.03 Move window to the monitor
  7. 2015.02.03 Useful Shortcuts in Eclipse
  8. 2015.02.02 Sharing session state over multiple services using StateServer
  9. 2015.02.02 Spring Framework Reference Documentation 4.1.4 RELEASE
  10. 2015.02.02 cglib - Byte Code Generation Library
  11. 2015.02.02 Prevent symptom that debugging does not reflect latest source code
  12. 2015.01.15 MVC Execution Flow
  13. 2015.01.15 JavaBeans, POJO, VO and DTO
  14. 2015.01.13 Set up spring MVC development environment using Luna
  15. 2014.12.14 Routing with WCF
  16. 2014.12.12 Web Garden and Web Farm
  17. 2014.12.04 Inversion Of Control (= Hollywood Principle)
  18. 2014.11.29 Stop thread using own flag and interrupt method
  19. 2014.11.29 AsEclipse extension
  20. 2014.11.29 Shortcut to "Navigate to ..."
2015. 5. 12. 04:28

Exception Handling in Spring MVC

The following link provides good explanation for exception handling in Spring MVC.


https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc


In addition, it also provides the sample to demonstrate it.


https://github.com/paulc4/mvc-exceptions


I recognized the ResponseStatus annotation is very useful to return abnormal http status.


@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such order")
public class OrderNotFoundException extends RuntimeException {

	/**
	 * Unique ID for Serialized object
	 */
	private static final long serialVersionUID = -8790211652911971729L;

	public OrderNotFoundException(String orderId) {
		super(orderId + " not found");
	}
}


In the case of using ControllerAdvice, the following code should be considered if you let other exceptions with ResponseStatus annotation  be handled as it is.


@ControllerAdvice
public class GlobalExceptionHandlingControllerAdvice {

	@ExceptionHandler(SupportInfoException.class)
	public ModelAndView handleError(HttpServletRequest req, Exception exception)
			throws Exception {

		// Rethrow annotated exceptions or they will be processed here instead.
		if (AnnotationUtils.findAnnotation(exception.getClass(),
				ResponseStatus.class) != null)
			throw exception;

		logger.error("Request: " + req.getRequestURI() + " raised " + exception);

		ModelAndView mav = new ModelAndView();
		mav.addObject("exception", exception);
		mav.addObject("url", req.getRequestURL());
		mav.addObject("timestamp", new Date().toString());
		mav.addObject("status", 500);

		mav.setViewName("support");
		return mav;
	}

}


mvc-exceptions.zip


2015. 4. 15. 23:34

Spring Security JSP Tag Libraries

Declaring the Taglib


<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>


The authorize Tag


<sec:authorize access="hasRole('supervisor')">

This content will only be visible to users who have the "supervisor" authority in their list

of <tt>GrantedAuthority</tt>s.

</sec:authorize>


<sec:authorize access="hasPermission(#domain,'read') or hasPermission(#domain,'write')">

This content will only be visible to users who have read or write permission to the Object found as a

request attribute named "domain".

</sec:authorize>


<sec:authorize url="/admin">

This content will only be visible to users who are authorized to send requests to the "/admin" URL.

</sec:authorize>


Disabling Tag Authorization for Testing


If you set the system property spring.security.disableUISecurity to true, the authorize tag will still run but will not hide its contents. By default it will also surround the content with <span class="securityHiddenUI">…</span> tags. This allows you to display "hidden" content with a particular CSS style such as a different background colour. Try running the "tutorial" sample  application with this property enabled, for example.


This can be tested by using the following sample:



tutorial-xml.zip


After downloading it, type the command as below (need to install gradle) :


gradle jettyRun -Dspring.security.disableUISecurity=true


If it succeeded to run, visit the "http://localhost:8080/sample". Then you will see the following page. 





The texts highlighted with orange background will be hidden if it's false.


The authentication Tag


<sec:authentication property="principal.username" />


You can access the Authentication object in your MVC controller

(by calling SecurityContextHolder.getContext().getAuthentication()) and add the data

directly to your model for rendering by the view.


The accesscontrolllist Tag


<sec:accesscontrollist hasPermission="1,2" domainObject="${someObject}">

This will be shown if the user has all of the permissions represented by the values "1" or "2" on the

given object.

</sec:accesscontrollist>



The csrfInput Tag


If CSRF protection is enabled, this tag inserts a hidden form field with the correct name and value for

the CSRF protection token. If CSRF protection is not enabled, this tag outputs nothing.

Normally Spring Security automatically inserts a CSRF form field for any <form:form> tags you use,

but if for some reason you cannot use <form:form>, csrfInput is a handy replacement.

You should place this tag within an HTML <form></form> block, where you would normally place

other input fields. Do NOT place this tag within a Spring <form:form></form:form> block—Spring

Security handles Spring forms automatically.


<form method="post" action="/do/something">

<sec:csrfInput />

Name:<br />

<input type="text" name="name" />

...

</form>


The csrfMetaTags Tag


If CSRF protection is enabled, this tag inserts meta tags containing the CSRF protection token form

field and header names and CSRF protection token value. These meta tags are useful for employing

CSRF protection within JavaScript in your applications.


You should place csrfMetaTags within an HTML <head></head> block, where you would normally

place other meta tags. Once you use this tag, you can access the form field name, header name, and

token value easily using JavaScript. JQuery is used in this example to make the task easier.


<!DOCTYPE html>

<html>

<head>

<title>CSRF Protected JavaScript Page</title>

<meta name="description" content="This is the description for this page" />

<sec:csrfMetaTags />

<script type="text/javascript" language="javascript">

var csrfParameter = $("meta[name='_csrf_parameter']").attr("content");

var csrfHeader = $("meta[name='_csrf_header']").attr("content");

var csrfToken = $("meta[name='_csrf']").attr("content");

// using XMLHttpRequest directly to send an x-www-form-urlencoded request

var ajax = new XMLHttpRequest();

ajax.open("POST", "http://www.example.org/do/something", true);

ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded data");

ajax.send(csrfParameter + "=" + csrfToken + "&name=John&...");

// using XMLHttpRequest directly to send a non-x-www-form-urlencoded request

var ajax = new XMLHttpRequest();

ajax.open("POST", "http://www.example.org/do/something", true);

ajax.setRequestHeader(csrfHeader, csrfToken);

ajax.send("...");

// using JQuery to send an x-www-form-urlencoded request

var data = {};

data[csrfParameter] = csrfToken;

data["name"] = "John";

...

$.ajax({

url: "http://www.example.org/do/something",

type: "POST",

data: data,

...

});

// using JQuery to send a non-x-www-form-urlencoded request

var headers = {};

headers[csrfHeader] = csrfToken;

$.ajax({

url: "http://www.example.org/do/something",

type: "POST",

headers: headers,

...

});

<script>

</head>

<body>

...

</body>

</html>


If CSRF protection is not enabled, csrfMetaTags outputs nothing.


References: spring-security-reference

2015. 4. 15. 05:56

Functional Testing and Non-Functional Testing

ISO 9126 introduces the following quality model :


  • Functionality 기능성

    • Suitability
provide an appropriate set of functions

    • Accuracy
provide the right or agreed results or effect

    • Interoperability
interact with one or more specified systems

    • Security
protect information and data so that unauthorised persons or systems cannot read or modify them and authorised persons or systems are not denied access to them.

    • Functionality Compliance


  • Reliability 신뢰성

    • Maturity
avoid failure as a result of faults

    • Fault Tolerance
maintain a specified level of performance

    • Recoverability
re-establish a specified level of performance and recover the data

    • Reliability Compliance


  • Usability 사용성

    • Understandability
enable the user to understand whether the software is suitable

    • Learnability
enable the user to learn its application.

    • Operability
enable the user to operate and control it

    • Attractiveness
attractive to the user

    • Usability Compliance


  • Efficiency 효율성

    • Time Behaviour
provide appropriate response and processing times and throughput rates

    • Resource Utilization
use appropriate amounts and types of resources

    • Efficiency Compliance


  • Maintainability 유지보수성

    • Analyzability
be diagnosed for deficiencies or causes of failures

    • Changeability
enable a specified modification to be implemented

    • Stability
avoid unexpected effects from modifications

    • Testability
enable modified software to be validated

    • Maintainability Compliance


  • Portability 이식성

    • Adaptability
be adapted for different specified environments without applying actions or means

    • Installability
be installed in a specified environment

    • Co-Existence
co-exist with other independent software

    • Replaceability
be used in place of another specified software product

    • Portability Compliance


Only Functionality of 6 items above is under Functional Testing. The rest is under Non-Functional Testing. 

References: 
- 자바 개발자도 쉽고 즐겁게 배우는 테스팅 이야기


2015. 4. 7. 23:24

Spring MVC and HDIV example application and Debugging

Source: https://github.com/hdiv/hdiv-spring-mvc-showcase.git            

Reference: http://javahotpot.blogspot.in/2013/11/running-tomcat-maven-plugin-in-debug.html


I'll explain how to add showcase sample into the eclipse from git repository above then how to set the debugging environment step by step. 


1. Make a eclipse project


  • Select Import from the context menu in the Navigator or Project Explorer
  • Navigate to the Git folder and select "Projects from Git"
  • Select "Clone URI" from the repository source page
  • Paste the following URI into the URI 
https://github.com/hdiv/hdiv-spring-mvc-showcase.git
  • Then click Next Until "Select a wizard to use for importing projects" page is shown
  • Select "Import s general project"
In my case, other option could not import any project
  • Finally click Finish.

2. Set up the debug environment for this sample

  • Open the context menu by clicking the right mouse button on the Navigator or Project explorer
  • Go to the "Debug As" menu and select the "Debug configurations..."
  • Select "Maven Build" like the following


  • Click the right mouse button on the "Maven Build" then select "New"
  • The new configuration will be made like the following then enter name as "Debug tomcat"


  • It's time to specify "Base directory". Click "Browse Workspace" and select "hdiv-spring-mvc-showcase" as shown in the following figure.


  • Then click the Source tab and click "Add" like the following


  • Select Project like the figure above then click OK. and select "hdiv-spring-mvc-showcase".
  • Finally press the "Debug" button. 

That's all. If you meet some error, try to build maven project then start debugging. If you finished all the steps above, you can easily start debugging by clicking the menu like the following:














2015. 3. 17. 02:03

Responsive Web

Here's good article :


http://helloworld.naver.com/helloworld/textyle/81480

2015. 2. 3. 23:13

Move window to the monitor

If you have more than one monitor:


  • Win + Shift + Left arrow : Move window to the monitor on the left
  • Win + Shift + Right arrow : Move window to the monitor on the right


As you know, there are the useful shortcuts for manipulating the active window:


  • Win + Left arrow : Snap to the left half of the screen
  • Win + Right arrow : Snap to the right half of the screen
  • Win + Up arrow: Maximize the window
  • Win + Down arrow: Minimize/Restore if it's maximized


2015. 2. 3. 00:04

Useful Shortcuts in Eclipse

Here are the shortcuts that is used very often  by me.


 Ctrl + Shift + O

 imports all classes in a file automatically

 Ctrl + O

 show code outline / structure

 Atl + Shift + F

 Correct indentation in a file

 Ctrl + I

 Correct indentation in a selection

 Ctrl + D delete a line

 Ctrl + 1

 Quick fix 

 Ctrl + B

 Build all. 

 Change this short cut to "Build Project" to save your time.

 F11 Debug
 Ctrl + F11 Run
 F3 Open declaration. Go to source.

 Alt + Left Arrow

 Go to back 

 Alt + Right Arrow 

 Go to forward 

 Ctrl + Shift + R

 Open resource like a file

 Ctrl + Shift + B

 Toggle break point

 Alt + Shift + J Add 
 Alt + Shift + E

 Show in navigator.

 Not default. Need to set this short cut by yourself

 Ctrl + K 

 Find next
 Ctrl + Shift + K Find previous 

 Ctrl + Shift + W

 Close others.
 Not default. Need to set this shout cut by yourself 

 Ctrl + H

 Show search dialog with various options

 Ctrl + / Toggle line comment 

 Ctrl + Shift + /

 Add block comment
 Ctrl + Shift + \

 Remove block comment 

 Alt + G

 Open implementation
 Alt + Shift + G Open super implementation


2015. 2. 2. 23:51

Sharing session state over multiple services using StateServer

For about a week I went through how to share session state over multiple services because our customers wanted to make their service to become HA (High availability). To construct our service as HA, sharing session state over multiple WAS was very important. And because we're using MySQL, using StateServer instead of SqlServer was unavoidable option.


It was really hard to find any document related to this knowledge. Finally I found very helpful site which gives simple solution to us. 


http://weblogs.asp.net/lichen/sharing-session-state-over-multiple-asp-net-applications-with-asp-net-state-server


Thanks to Li Chen. In addition to the link, I made sample project to show this. Here it is.



StateSeverTest.zip



To run this example, you have to start "ASP.NET State Service" as below:


1. Type Windows + R and type the "services.msc"


2. Find the "ASP.NET State Service"





3. Start that service


That's it. 


Updated at 2015.02.02


In case of WCF, to share session between difference wcf services routed by wcf routing, you should set SoapProcessingEnabled option to false. (Thanks to my smart colleague, Mr. Oh)


Refer the following for more information:


https://msdn.microsoft.com/en-us/library/ee816917(v=vs.110).aspx


2015. 2. 2. 23:46

Spring Framework Reference Documentation 4.1.4 RELEASE

Here is the official spring framework reference document:



spring-framework-reference.pdf


http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/pdf/spring-framework-reference.pdf



2015. 2. 2. 23:42

cglib - Byte Code Generation Library

cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

https://github.com/cglib/cglib/wiki


Here is good example for this:


http://markbramnik.blogspot.kr/2010/04/cglib-introduction.html


In addition, I attached sample project to be able to run his explanation:



CglibTest.zip



TODO: I need to investigate and study cglib's usage more!


It's now widely used at famous frameworks like Hibernate, Spring and more.

2015. 2. 2. 23:29

Prevent symptom that debugging does not reflect latest source code

Some times eclipse did not seems to launch applications well in debugging. 


You might experience like debugging did not reflect latest source code you just edited. Though you set the break point into the line you want, next step by pressing F6 for stepping over, break point hit the wrong line. 


Mostly this is caused by not saving the source codes. By default, eclipse does not prompt before launching the application though it's not still saved.


To prevent this mistake, I recommend to set the following two option!


1. Save automatically before build


Window > Preferences > General > Workspace


  • Check 'Save automatically before build' like the following:






2. Save required dirty editors before launching : Prompt



Window > Preferences > Run/Debug > Launching


  • Set an option to 'Prompt' like the following for 'Save required dirty editors before launching' option.



This trivial two options will reduce your complaint against eclipse!



2015. 1. 15. 23:24

MVC Execution Flow



Referenced : 열혈강의 자바 웹 개발 워크북

2015. 1. 15. 22:59

JavaBeans, POJO, VO and DTO

JavaBeans


JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.
  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion that is independent of the VM and platform.

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming 


POJO (Plain Old Java Object)


POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean (especially before EJB 3). The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, and PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl.

The term has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks. A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

As designs using POJOs have become more commonly-used, systems have arisen that give POJOs some of the functionality used in frameworks and more choice about which areas of functionality are actually needed. Hibernate and Spring are examples.


VO (Value Object)


In Patterns of Enterprise Application Architecture I described Value Object as a small object such as a Money or date range object. Their key property is that they follow value semantics rather than reference semantics.

You can usually tell them because their notion of equality isn't based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique - for example currency codes for currency objects are enough to test equality.

A general heuristic is that value objects should be entirely immutable. If you want to change a value object you should replace the object with a new one and not be allowed to update the values of the value object itself - updatable value objects lead to aliasing problems.

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.

You can find some more good material on value objects on the wiki and by Dirk Riehle.


DTO (Data Transfer Object)


Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).

In a traditional EJB architecture, DTOs serve dual purposes: first, they work around the problem that entity beans are not serializable; second, they implicitly define an assembly phase where all data to be used by the view is fetched and marshalled into the DTOs before returning control to the presentation tier.


2015. 1. 13. 23:03

Set up spring MVC development environment using Luna

This guide sets up Spring MVC development environment with maven


1. Download eclipse luna


http://www.eclipse.org/luna/


2. Install STS (Spring Tool Suite)


  • Run eclipse
  • Find the Help > Eclipse Marketplace menu on toolbar
  • Type 'sts' on Search tab
  • Click 'install' button which title is 'Spring Tool Suite (STS) for Eclipse Luna ~~~~
  • Restart eclipse

3. Install maven plugin

  • Find the Help > Eclipse Marketplace menu on toolbar
  • Type 'm2e' on Search tab
  • Click 'install' button which title is 'Maven Integration for Eclipse (Luna) 1.5.0'
    • If this was already installed, the buttons are Update and Uninstall. If so, skip this step.
  • Restart eclipse

4. Create Spring MVC Project

  • File > New > Project
  • Type the spring then select 'Spring Project'
  • Select the 'Spring MVC Project' template and specify a project name
  • Proceed nexts until you met the dialog that asks package name
  • Enter any package name and finish it.



2014. 12. 14. 16:56

Routing with WCF


Here is sample code for routing with WCF.



WCFRoutingServiceTest.zip







Web.config for service 


<?xml version="1.0"?>


<!--

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  -->


<configuration>

  <system.web>

    <compilation debug="true" targetFramework="4.0" >

      <assemblies>

        <add assembly="System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

      </assemblies>

    </compilation>

  </system.web>

  <system.serviceModel>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">

      <serviceActivations>

        <add relativeAddress="RiskManagementServiceUAT.svc" service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      </serviceActivations>

    </serviceHostingEnvironment>

    <services>

      <!--ROUTING SERVICE -->

      <service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="routerConfig">

        <endpoint address=""

                  binding="basicHttpBinding"

                  contract="System.ServiceModel.Routing.IRequestReplyRouter"

                  name="reqReplyEndpoint" />

      </service>

    </services>


    <routing>

      <filters>

        <filter name="matchAll" filterType="MatchAll" />

      </filters>


      <filterTables>

        <filterTable name="routingTable">

          <add filterName="matchAll" endpointName="RiskService" backupList="RiskServiceBackup" />

        </filterTable>

      </filterTables>

      <backupLists>

        <backupList name="RiskServiceBackup">

          <add endpointName="RiskService2"/>

        </backupList>

      </backupLists>

    </routing>


    <behaviors>

      <serviceBehaviors>

        <behavior name="routerConfig">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

          <routing routeOnHeadersOnly="false" filterTableName="routingTable" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <client>

      <!-- Define the client endpoint(s) to route messages to -->

      <endpoint name="RiskService"

            address="http://localhost:81/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

      <endpoint name="RiskService2"

            address="http://localhost:82/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

    </client>

  </system.serviceModel>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>

</configuration>



client.config for silverlight client  


<configuration>

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"

                    maxReceivedMessageSize="2147483647">

                    <security mode="None" />

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="http://localhost/RiskManagementServiceUAT.svc" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"

                name="BasicHttpBinding_IService1" />

        </client>

    </system.serviceModel>

</configuration> 


* I updated source to make someone to understand better.



WCFRoutingServiceTest_updated.zip



* Address filter decides where to go using client's ip address. Like the sticky session under L4 load balancer, address filter ensures client to be directed to same was.



WCFRoutingServiceTest_addressfilter.zip



References:


2014. 12. 12. 05:34

Web Garden and Web Farm

Web Garden 


Web application deployed on a server with multiple processors


Web Farm


Web application deployed on multiple server


References : http://www.youtube.com/watch?v=z4rpYK4DNoI

2014. 12. 4. 12:14

Inversion Of Control (= Hollywood Principle)

Simply it means,



"Don't call us, we'll call you."



In case of the library, you would call its API but, A framework would call your implementation. In addition, a framework would control to create and destroy an object instead of you.


Template method which is one of the GOF patterns is very related to this.


  • Helpful sites:


http://martinfowler.com/bliki/InversionOfControl.html

http://vandbt.tistory.com/43

2014. 11. 29. 05:46

Stop thread using own flag and interrupt method

Here is the sample code that explains how to stop thread using own flag and interrupt method respectively.


public class Main {

	static interface IClosableThread {
		void start();

		void close();
	}

	static class StopThreadUsingFlag extends Thread implements IClosableThread {
		private boolean stopThis = false;

		public void run() {
			try {
				while (this.stopThis == false) {
					System.out.print(".");
					Thread.sleep(500);
				}
			} catch (InterruptedException e) {
			}

			System.out.println();
			System.out.println("Finished!");
		}

		public void close() {
			this.stopThis = true;

			try {
				this.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	static class StopThreadUsingInterrupt extends Thread implements
			IClosableThread {
		public void run() {
			try {
				while (!this.isInterrupted()) {
					System.out.print(".");
					Thread.sleep(500);
				}
			} catch (InterruptedException e) {
			}

			System.out.println();
			System.out.println("Finished!");
		}

		public void close() {
			this.interrupt();

			try {
				this.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		System.out.println("Hello, Java!");

		IClosableThread thread = new Main.StopThreadUsingFlag();
		thread.start();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.close();

		thread = new Main.StopThreadUsingInterrupt();
		thread.start();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.close();

	}
}


2014. 11. 29. 05:38

AsEclipse extension

When using eclipse, ctrl + o is very usefull to move to the member within a file. AsEclipse supports this feature. 


Here are the description for AsEclipse and link to it.


AsEclipse is an add-in for MS Visual Studio, which enables you to use some convenient Eclipse editing functions in MS Visual Studio with almost the same shortcut keys. No matter whether you are familiar with Eclipse, AsEclipse will be helpful in coding with VS.

https://visualstudiogallery.msdn.microsoft.com/99ede732-544c-4f3b-8e38-49e4b8395075/


2014. 11. 29. 05:16

Shortcut to "Navigate to ..."

To find something like class, function, or file in a solution, "Navigate to..." is very useful. 


Ctrl + , 


lets you direct to that dialog.