public class WrapperTest {
static {
print(10);
}
static void print(int x) {
System.out.println(x);
System.exit(0);
}
}
In the above code System.exit(0) is used to stop the program. What argument does that method take? Why do we gave it as 0. Can anyone explain the concept?Thanks.
Consider an object declared in a method:
public void foo() {
final Object obj = new Object();
// A long run job that consumes tons of memory and
// triggers garbage collection
}
Will obj be subject to garbage collection before foo() returns?
UPDATE:
Previously I thought obj is not subject to garbage collection until foo() returns.
However, today I find myself wrong.
I have spend several hours in fixing a bug and finally found the problem is caused by obj garbage collected!
Can anyone explain why this happens? And if I want obj to be pinned how to achieve it?
Here is the code that has problem.
public class Program
{
public static void main(String[] args) throws Exception {
String connectionString = "jdbc:mysql://<whatever>";
// I find wrap is gc-ed somewhere
SqlConnection wrap = new SqlConnection(connectionString);
Connection con = wrap.currentConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
ResultSet rs = stmt.executeQuery("select instance_id, doc_id from
crawler_archive.documents");
while (rs.next()) {
int instanceID = rs.getInt(1);
int docID = rs.getInt(2);
if (docID % 1000 == 0) {
System.out.println(docID);
}
}
rs.close();
//wrap.close();
}
}
After running the Java program, it will print the following message before it crashes:
161000
161000
********************************
Finalizer CALLED!!
********************************
********************************
Close CALLED!!
********************************
162000
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
And here is the code of class SqlConnection:
class SqlConnection
{
private final String connectionString;
private Connection connection;
public SqlConnection(String connectionString) {
this.connectionString = connectionString;
}
public synchronized Connection currentConnection() throws SQLException {
if (this.connection == null || this.connection.isClosed()) {
this.closeConnection();
this.connection = DriverManager.getConnection(connectionString);
}
return this.connection;
}
protected void finalize() throws Throwable {
try {
System.out.println("********************************");
System.out.println("Finalizer CALLED!!");
System.out.println("********************************");
this.close();
} finally {
super.finalize();
}
}
public void close() {
System.out.println("********************************");
System.out.println("Close CALLED!!");
System.out.println("********************************");
this.closeConnection();
}
protected void closeConnection() {
if (this.connection != null) {
try {
connection.close();
} catch (Throwable e) {
} finally {
this.connection = null;
}
}
}
}
I have added reference to my application of Microsoft.Office.Server as well as Microsoft.Sharepoint . but while importing the namespace in program , there is no option like
microsoft.office.server.search.query after microsoft.office.server.search. I am getting their Microsoft.Office.Server.Search.PortalCrawl;. Why this is?? please guide me.
hi
i try to install my C# program on Windows 7 64bit and i got error.
i need to install MDAC and ActiveSync on computer.
from where i can download MDAC (that fit for Win-7 64 bit) and ActiveSync ?
thank's in advance
have to check some formulae whether they are providing correct result, these formula are written part of a VB program, what is the best tool\method to unit test these formula?
I'm looking to export a page that looks good in print media, to word.
Can this be done automatically, or mostly automatically with office apis?
The alternative is to create a program that reads all our style meta data and font meta data and convert to word and force a download.
The issue is our style metadata is already built for css, its a web app after all. And writing my own css parser, doesn't sound like a good use of time.
Is there a free or open source library to read Excel files (.xls) directly from a C# program?
It does not need to be too fancy, just to select a worksheet and read the data as strings. So far, I've been using Export to Unicode text function of Excel, and parsing the resulting (tab-delimited) file, but I'd like to eliminate the manual step.
How do you take a commmand like this in PowerShell and split it across multiple lines:
&"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:contentPath="c:\workspace\xxx\master\Build\_PublishedWebsites\xxx.Web" -dest:contentPath="c:\websites\xxx\wwwroot\,computerName=192.168.1.1,username=administrator,password=xxx"
I would like to dynamically allocate memory from an assembly
program that does not link against the standard C library.
Since brk(2) and sbrk(2) are unavailable on Mac OS X (10.6.2),
what are the alternatives?
(I'm guessing that it involves a Mach call, but there seems to
be little documentation around that)
Hello
Can any one help me to find out, how I can setup Hessian Kit on existing iPhone project. What are the steps required to run a simple hello world program.
I have Hessian Kit (http://sourceforge.net/projects/hessiankit/) but don't know how I can include this in my existing project.
Please help
Thanks
SD
what is this exception and how to remove this
in my problem i am creating an arraylist of objects, and after checking some condition,i want to remove some objects. but the program is giving this exception ConcurrentModificationException. how to remove this
thanks in advance
program runs fine. When I put a breakpoint a segmentation fault is generated. Is it me or GDB? At run time this never happens and if I instantiate only one object then no problems.
Im using QtCreator on ubuntu x86_64 karmic koala.
After watching the tier 1 video, where do I go to learn how to program in C#?
Is there an online video series?
Usually people say to "Read the Manual", but what is a manual these days? Do I just say "Help", "View Help" and start grokking?
i have a winsock component made with vb.net in a class library that has events.
how do i make it appear in tool box if i reference the dll in another project.?
How do i use it in my c# program?
thanks
Hi,
I'm a beginner in java. I want the logic of the small program.
I have two arrays
array = {a1,a2,a3,a4,a5,,,,,,,,,an}
and
array2 = {b1,b2,b3,b4,,,,,,,,,,,bn}
I want string as:
a1b1,a2a3b2b3,a4a5a6b4b5b6,..........an
Please tell me what will be the logic.
Hello!
Where can I find centralized and complete documentation aboput Linux - specific API?
I'm preparing Linux port of my application and i want to use as much Linux - specific features as it's possible. So far I found that Linux provide epoll and inotify API, which are great news for me, because my program works as network server and monitor local file systems.
In their dev site,AOL says the contacts api would coming soon from the year 2008-_-
but I can't find anything about it since then, and I find in window live add contacts site:
http://cid-7b76c1c8e1ade1ea.profile.live.com/connect/
They have a program to port contacts from AOL, that is this only for Microsoft. Is there another method to do this?
In order to refactor some methods into smaller ones, I need pass by reference, since I can only have one return type. I could create a different return or parameter type whenever I need to do this, but then I'd end up with a bunch of bloated, seemingly unnecessary classes.
What is the best alternative here, besides redesigning the program, which can't be done?
I am using Android HoneyComb.I need to execute some tasks parallely and I am using AsyncTask's
public final AsyncTask executeOnExecutor (Executor exec, Params... params) method.In each separate thread I am computing some values and I need to store then in an ArrayList.I must then sort all the values in the arrayList and then display it in the UI.Now my question is if one of the thread gets completed earlier than the other then will it immediately call the onPostExecute method or onPostExecute method will be called after all the background threads have been completed?MY program implementation depends on what occurs here.
I've done a lot of research on when it's correct to release things, but it's all confusing to me. I think sometimes the Leaks program is off. Anyway...
background is a UIImageView
background.image = [UIImage imageNamed:@"greenbackground.png"];
Do I have to release background? I never alloced it and it's not set as a property, so I'm thinking no.
Hi,
I have a vb app working now but many users have complained to me that it requires .net library installed. Is there a way to bundle it with my program without having a seperate exe?
Is there a recognized, recommended, or standard form for representing the structure of JSON? E.g., my service returns a structure, effectively, represented as JSON. How do I describe what my service returns, such that another service can consume that JSON and program to its interface?
Is there a definitive guide for special folders in windows? An internet search yielded just a few crumbs of information, e.g.
Wikipedia:Special Folders
Windows 7 Client Software Logo Program
What I'm looking for is an explanation of each folder, its intended purpose, usage scenarios and motivation for its existence (e.g. what does Local App settings provide for that App settings doesn't). A matrix/table of requirements/uses against folder would be handy I think.
This isn't tech support. I'm wondering if anyone else has seen a cursor like mine before. I don't know what it's called or if it's related to a program I'm using etc.
Who can name the phantom cursor?