Unix Tail implementation with Java
1. 구현 소스
package client;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
public class Tail
{
public static void main(String[] args) throws IOException
{
BufferedReader input = null;
Reader fileReader = null;
if (args != null && args.length > 0) {
fileReader = new FileReader(args[0]);
input = new BufferedReader(fileReader);
String line = null;
while (true) {
if ((line = input.readLine()) != null) {
System.out.println(line);
continue;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
} else {
System.out.println("입력 값을 확인 해 주세요.");
}
try {
if (input != null)
input.close();
if (fileReader != null)
fileReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
2. 실행 결과
Javascript기반의 Pagination
1. Jquery 에서 사용
- 다운 로드 : http://plugins.jquery.com/project/pagination
- 사용 소스
- 다운 로드 : http://plugins.jquery.com/project/pagination
- 사용 소스
<script type="text/javascript">
function pageselectCallback(page_id, jq){
$('#Searchresult').text("Showing search results "
+((page_id*10)+1)+"-"+((page_id*10)+10));
}
$(document).ready(function(){ // Create pagination element
$("#Pagination").pagination(300, {
num_edge_entries: 2,
num_display_entries: 8,
callback: pageselectCallback
});
// Set handler for setting pagination options via form
$("#setoptions").click(function(){
var opt = {callback: pageselectCallback};
$("input[@type=text]").each(function(){
opt[this.name] = this.className.match
(/numeric/)?parseInt(this.value):this.value;
});
// extract maxitems
var maxitems = opt.maxitems;
delete opt.maxitems;
// Avoid html injections in this demo
var htmlspecialchars =
{ "&":"&", "<":"<", ">":">", '"':"""}
$.each(htmlspecialchars, function(k,v){
opt.prev_text = opt.prev_text.replace(k,v);
opt.next_text = opt.next_text.replace(k,v);
})
$("#Pagination").pagination(maxitems, opt);
});
});
</script>
- 데모 : http://www.mimul.com/examples/pagenation/demo.htm
2. 일반 Javascript에서 사용
- 사용 소스
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;
this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;
this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
return;
}
var oldPageAnchor = document.getElementById('pg'+
this.currentPage);
oldPageAnchor.className = 'pg-normal';
this.currentPage = pageNumber;
var newPageAnchor = document.getElementById('pg'+
this.currentPage);
newPageAnchor.className = 'pg-selected';
var from = (pageNumber - 1) * itemsPerPage + 1;
var to = from + itemsPerPage - 1;
this.showRecords(from, to);
}
this.prev = function() {
if (this.currentPage > 1)
this.showPage(this.currentPage - 1);
}
this.next = function() {
if (this.currentPage < this.pages) {
this.showPage(this.currentPage + 1);
}
}
this.init = function() {
var rows = document.getElementById(tableName).rows;
var records = (rows.length - 1);
this.pages = Math.ceil(records / itemsPerPage);
this.inited = true;
}
this.showPageNav = function(pagerName, positionId) {
if (! this.inited) {
alert("not inited");
return;
}
var element = document.getElementById(positionId);
var pagerHtml = '<span onclick="' + pagerName +
'.prev();" class="pg-normal"> « Prev </span> | ';
for (var page = 1; page <= this.pages; page++)
pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="'
+ pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
pagerHtml += '<span onclick="'+
pagerName+'.next();" class="pg-normal"> Next »</span>';
element.innerHTML = pagerHtml;
}
}
Java 5에서 String Concatenation과 StringBuffer의 속도 비교
JDK 1.4에서와 JDK 1.5에서 문자열을 결합할 경우 똑같은 상황이 올까요? ^^
1. 예제 소스
package client;
public class StringTest
{
public interface Repeatable {
void iteration(long loopId);
}
public static long repeat(int times, Repeatable repeatable) {
long initial = System.currentTimeMillis();
for (long c = 1; c <= times; c++)
repeatable.iteration(c);
long elapsed = System.currentTimeMillis() - initial;
return elapsed;
}
private static Repeatable stringBufferTest = new Repeatable()
{
public void iteration(long loopId) {
String alias = "a";
StringBuffer query = new StringBuffer(300);
query.append("SELECT ");
query.append(alias).append(".userName, ");
query.append(alias).append(".registerDate, ");
query.append("sum(").append(alias).append(".duration), ");
query.append(alias).append(".id FROM ");
query.append(StringTest.class.getName())
.append(" as ").append(alias);
query.append(" ORDER BY ")
.append(alias).append(".registerDate desc ");
String result = query.toString();
}
};
private static Repeatable stringConcatenationTest = new Repeatable()
{
public void iteration(long loopId) {
String query =
"SELECT " +
"a.userName, " +
"a.registerDate, " +
"sum(a.duration), " +
"a.id " +
"FROM " +
StringTest.class.getName() +
" as a " + "ORDER BY " +
"a.registerDate desc";
String result = query;
}
};
public static void main(String[] args) {
int times = 1000000;
long stringBuffElapsed, stringConcatElapsed;
for (int loopCount = 1; loopCount <= 5; loopCount++)
{
stringBuffElapsed = repeat(times, stringBufferTest);
stringConcatElapsed = repeat(times, stringConcatenationTest);
System.out.println("반복 횟수 " + loopCount);
System.out.println("StringBuffer 처리 시간 : " + stringBuffElapsed);
System.out.println("String Concatenation 처리 시간 : " +
stringConcatElapsed + "\n");
}
}
}
2. 예제 결과
3. 의견
- String객체는 immutable, StringBuffer는 mutable
- Stringr constant expression... 컴파일시에 결정되어, StringBuffer non-constant expression..런타임에 결정된다.
위의 String Concatenation이 StringBuffer보다 두배이상 빠르게 나오네요. 변수의 값이 런타임에 결정되는 것일 경우 StringBuffer, 아닐 경우는 String Concatenation을 사용하세요.
Top 125 Blogs for Development Managers
Development Managers 관련된 우수 블로거들을 순위별로 발표했네요. 괜찮다고 생각하시는 블로그의 RSS를 등록하여 자기 발전에 도움이 되세요. ^^
| Nr | Site / Author | PR | TA | AR | Hits | Cmts |
| 1 | Joel on Software Joel Spolsky | 7 | 2357 | 40364 | 6090 | |
| 2 | Coding Horror Jeff Atwood | 6 | 3472 | 54474 | 3870 | 1916 |
| 3 | Seth's Blog Seth Godin | 7 | 8757 | 93669 | 14600 | |
| 4 | Paul Graham: Essays Paul Graham | 6 | 2382 | 49839 | 2750 | |
| 5 | blog.pmarca.com Marc Andreesen | 7 | 1169 | 95439 | 3350 | |
| 6 | Rough Type Nicholas Carr | 7 | 1114 | 109196 | 4910 | 111 |
| 7 | Scott Hanselman's Computer Zen Scott Hanselman | 5 | 1284 | 51568 | 4040 | 155 |
| 8 | Martin Fowler's Bliki Martin Fowler | 6 | 376 | 79142 | 2240 | |
| 9 | Rands in Repose Michael Lopp | 6 | 565 | 199191 | 1610 | 401 |
| 10 | Stevey's Blog Rants Steve Yegge | 7 | 182 | 201319 | 1270 | 912 |
| 11 | Bokardo: Social Design Joshua Porter | 6 | 448 | 105072 | 1990 | 122 |
| 12 | Eric.Weblog() Eric Sink | 6 | 161 | 219875 | 1820 | 183 |
| 13 | Lambda the Ultimate (various) | 6 | 197 | 172624 | 2150 | 90 |
| 14 | Otaku, Cedric's Weblog Cedric | 7 | 107 | 209562 | 942 | 274 |
| 15 | PragDave Dave Thomas | 6 | 56 | 1700 | 158 | |
| 16 | High Scalability (various) | 6 | 611 | 67614 | 749 | 57 |
| 17 | The Berkun Blog Scott Berkun | 6 | 224 | 150787 | 1120 | 42 |
| 18 | UIE Brain Sparks Jared Spool | 6 | 128 | 73839 | 913 | 34 |
| 19 | Raganwald Reginald Braithwaite | 5 | 286 | 295168 | 591 | 120 |
| 20 | J.D. Meier's Blog J.D. Meier | 6 | 106 | 446 | 32 | |
| 21 | Stack Overflow Jeff Atwood | 6 | 234 | 99548 | 119 | 292 |
| 22 | Stevenf.com Steven Frank | 5 | 211 | 431730 | 711 | |
| 23 | secretGeek Leon Bambrick | 5 | 109 | 279144 | 382 | 78 |
| 24 | CodeBetter.Com (various) | 5 | 804 | 55474 | 140 | 53 |
| 25 | Interoperability Happens Ted Neward | 6 | 155 | 871230 | 570 | 42 |
| 26 | Gray's Matter Justice Gray | 5 | 89 | 302785 | 607 | 38 |
| 27 | Mike Cohn's Blog: Succeeding with Agile Mike Cohn | 5 | 401141 | 264 | 116 | |
| 28 | Object Mentor Blog (various) | 5 | 83 | 281113 | 248 | 84 |
| 29 | James Bach’s Blog James Bach | 5 | 45 | 657727 | 503 | 159 |
| 30 | Managing Product Development Johanna Rothman | 6 | 50 | 710781 | 1020 | 22 |
| 31 | Google Testing Blog (various) | 5 | 151 | 308629 | 216 | 45 |
| 32 | Alistair Cockburn Alistair Cockburn | 5 | 636969 | 426 | ||
| 33 | Tyner Blain Scott Sehlhorst | 5 | 63 | 873747 | 594 | 40 |
| 34 | Artima Weblogs (various) | 5 | 250 | 41092 | 97 | 21 |
| 35 | It's Just a Bunch of Stuff That Happens Eric Burke | 5 | 401 | 338795 | 109 | 51 |
| 36 | { |one, step, back| } Jim Weirich | 5 | 92 | 699777 | 315 | |
| 37 | Dr. Dobb's CodeTalk (various) | 6 | 249123 | 732 | 6 | |
| 38 | Petzold Book Blog Charles Petzold | 5 | 23 | 400444 | 362 | 67 |
| 39 | {Codesqueeze} Max Pool | 5 | 77 | 432030 | 172 | 56 |
| 40 | Signal vs. Noise (various) | 4 | 72462 | 211 | 220 | |
| 41 | Curious Cat John Hunter | 5 | 44 | 96174 | 1030 | 4 |
| 42 | Knowing.NET Larry O'Brien | 5 | 48 | 601544 | 482 | 12 |
| 43 | Agile Management Blog David Anderson | 5 | 26 | 655893 | 1200 | 15 |
| 44 | /\ndy Andy Hunt | 6 | 28 | 1717994 | 769 | 21 |
| 45 | James Shore: Successful Software James Shore | 5 | 71 | 1331837 | 221 | 28 |
| 46 | Object Technology Jeff Sutherland | 6 | 85 | 500221 | 186 | 6 |
| 47 | Better Projects Craig Brown | 5 | 38 | 1080915 | 251 | 21 |
| 48 | Evolving Web Jim Benson | 5 | 42 | 1681730 | 708 | 16 |
| 49 | Meme Agora Neal Ford | 5 | 63 | 2160111 | 247 | 28 |
| 50 | Agility@Scale Scott W. Ambler | 5 | 70 | 68 | ||
| 51 | David Chelimsky David Chelimsky | 5 | 838069 | 103 | 62 | |
| 52 | Pure Danger Tech Alex Miller | 5 | 70 | 596549 | 163 | 9 |
| 53 | Elegant Code (various) | 5 | 96 | 497139 | 72 | 18 |
| 54 | Exploring Solutions Spaces C. Keith Ray | 6 | 13 | 1392656 | 329 | |
| 55 | The Braidy Tester Micahel | 5 | 21 | 344 | 9 | |
| 56 | Destraynor Des Traynor | 5 | 16 | 966603 | 169 | 58 |
| 57 | Project Shrink Bas de Baar | 4 | 40 | 141635 | 237 | 18 |
| 58 | Stephans Blog Stephan Schmidt | 5 | 32 | 659770 | 56 | 87 |
| 59 | Agile Advice (various) | 5 | 64 | 899353 | 339 | 2 |
| 60 | LeadingAnswers Mike Griffiths | 4 | 38 | 1254375 | 456 | 30 |
| 61 | Wide Awake Developers Michael Nygard | 5 | 292 | 1072770 | 149 | 4 |
| 62 | Bit-Player Brian Hayes | 6 | 12 | 3504554 | 240 | 65 |
| 63 | Word Aligned Thomas Guest | 5 | 57 | 536114 | 43 | 21 |
| 64 | Testing Hotlist Update Bret Pettichord | 5 | 14 | 1409810 | 231 | 29 |
| 65 | NOOP.NL: Managing Software Development Jurgen Appelo | 4 | 73 | 692206 | 181 | 19 |
| 66 | Caffeinated Coder Russell Ball | 5 | 52 | 1558998 | 46 | 86 |
| 67 | GrokCode Jess | 4 | 109 | 524914 | 46 | 74 |
| 68 | Lean Software Engineering Corey Ladas | 4 | 42 | 1112902 | 322 | 19 |
| 69 | Exploration Through Example Brian Marick | 5 | 31 | 3491602 | 224 | 27 |
| 70 | Herding Cats Glen Alleman | 5 | 51 | 1434425 | 70 | 23 |
| 71 | Legends of the Sun Pig Martin Sutherland | 7 | 4 | 1453763 | 399 | 14 |
| 72 | Agile Developer Venkat's Blog Venkat Subramaniam | 5 | 34 | 1152021 | 187 | 9 |
| 73 | The Third Bit Esan | 5 | 44 | 1084414 | 321 | 1 |
| 74 | Implementing Scrum Mike Vizdos | 5 | 53 | 946336 | 206 | 3 |
| 75 | Collaborative Software Testing Jonathan Kohl | 5 | 26 | 3279595 | 296 | |
| 76 | Test Obsessed Elisabeth Hendrickson | 4 | 34 | 2117127 | 256 | 41 |
| 77 | 10x Software Development Steve McConnell | 4 | 0 | 533 | 108 | |
| 78 | Joel Pobar's Weblog Joel Pobar | 5 | 21 | 6854408 | 139 | 94 |
| 79 | Creative Chaos Matthew Heusser | 5 | 28 | 3038531 | 294 | 11 |
| 80 | Jcooney.NET Joseph Cooney | 5 | 33 | 2194958 | 161 | 15 |
| 81 | All About Agile Kelly Waters | 4 | 31 | 408534 | 223 | 10 |
| 82 | Project Management 2.0 Andrew Filev | 5 | 12 | 272 | 5 | |
| 83 | Agile Commons (various) | 5 | 686263 | 148 | 4 | |
| 84 | The Cutter Blog (various) | 5 | 6 | 778348 | 304 | 7 |
| 85 | Chris Spagnuolo's GeoScrum Chris Spagnuolo | 5 | 51 | 2259995 | 198 | 4 |
| 86 | Aligning Technology, Strategy, People & Projects Eric Brown | 4 | 44 | 1245105 | 206 | 12 |
| 87 | Agile Software Development (various) | 4 | 62 | 331003 | 100 | 7 |
| 88 | Clarke Ching - More Chilli Please Clarke Ching | 5 | 36 | 2456889 | 280 | 3 |
| 89 | Musings of a Software Development Manager Ed Gibbs | 4 | 11 | 1538525 | 252 | 29 |
| 90 | Notes from a Tool User Mark Levison | 4 | 23 | 1383460 | 134 | 24 |
| 91 | Silk and Spinach Kevin Rutherford | 5 | 9 | 1117088 | 121 | 14 |
| 92 | Focused Performance Frank Patrick | 4 | 7 | 729258 | 1140 | 6 |
| 93 | Hot Needle of Inquiry Ron Jeffries | 4 | 11 | 273831 | 694 | 0 |
| 94 | Mistaeks I Hav Made Nat Pryce | 5 | 18 | 187328 | 94 | 0 |
| 95 | Agile Thoughts Tobias Mayer | 4 | 21 | 1782189 | 80 | 101 |
| 96 | Agile Chronicles (various) | 5 | 2680922 | 131 | 9 | |
| 97 | Steve Rowe's Blog Steve Rowe | 4 | 20 | 119 | 20 | |
| 98 | Kevin Dente's Blog Kevin Dente | 4 | 22 | 40 | 92 | |
| 99 | Agile CMMI Blog Hillel Glazer | 5 | 8 | 3340384 | 164 | 12 |
| 100 | Andrew Tokeley Andrew Tokeley | 4 | 28 | 1348226 | 64 | 20 |
| 101 | Information Technology Dark Side David Christiansen | 4 | 41 | 1838236 | 93 | 16 |
| 102 | Jonathan Babcock Jonathan Babcock | 4 | 12 | 356837 | 59 | 14 |
| 103 | Wayne Allen's Weblog Wayne Allen | 4 | 32 | 82 | 12 | |
| 104 | Brad Appleton's ACME Blog Brad Appleton | 4 | 19 | 2819226 | 505 | 5 |
| 105 | Agile in Action Simon Baker | 4 | 32 | 1866089 | 116 | 10 |
| 106 | Red Squirrel Reflections Dave Hoover | 5 | 8 | 2332736 | 106 | |
| 107 | You'd think with all my video game experience... Jason Yip | 5 | 21 | 5287734 | 195 | 2 |
| 108 | PierG Piergiorgio Grossi | 5 | 8 | 3549551 | 113 | 9 |
| 109 | Raven's Brain Raven Young | 4 | 44 | 5041095 | 342 | 0 |
| 110 | Software Project Management Pawel Brodzinski | 4 | 23 | 1694265 | 95 | 8 |
| 111 | HTMList.com (various) | 3 | 18 | 395560 | 53 | 19 |
| 112 | Effective Software Development Dave Nicolette | 4 | 18 | 184 | 1 | |
| 113 | Jeff Patton's Holistic Product Design & Development Jeff Patton | 4 | 1391393 | 92 | ||
| 114 | I.M. Wright’s “Hard Code” Eric Brechner | 4 | 0 | 66 | 51 | |
| 115 | /var/log/mind Dhananjay Nene | 2 | 13 | 676449 | 6 | 94 |
| 116 | George Dinwiddie's Blog George Dinwiddie | 4 | 11 | 6163238 | 123 | 16 |
| 117 | Agile Software Process Improvement Jason Gorman | 4 | 20 | 865398 | 75 | 0 |
| 118 | Thoughts On... William Caputo | 4 | 13 | 4397849 | 113 | 5 |
| 119 | Cauvin Roger L. Cauvin | 4 | 7 | 2583163 | 98 | 8 |
| 120 | You Want IT When? Bill Miller | 4 | 2039808 | 57 | 7 | |
| 121 | Steve Freeman Steve Freeman | 4 | 12 | 5584864 | 45 | 19 |
| 122 | Jbrains.ca J.B. Rainsberger | 5 | 0 | 15073372 | 117 | |
| 123 | Leading Agile Mike Cottmeyer | 3 | 10 | 4452233 | 125 | 6 |
| 124 | Corporate Coder Eric Landes | 4 | 2 | 60 | 2 | |
| 125 | Ivar Jacobson's Blog Ivar Jacobson | 3 | 3 | 16938712 | 42 | 17 |
OPML을 다운 받으실려면 여기를 클릭하세요.








