G*****h 发帖数: 33134 | 1 t.cc:
void getInt(int *p)
{
*p = 0;
}
bool silly()
{
bool b;
getInt((int *)&b);
return b;
}
int main()
{
return (int)silly();
} |
|
j****g 发帖数: 597 | 2 so my question is,
when the buffer is full, and getInt is invoked, it will notifyAll, releasing
the putInt that was blocked on the wait.
If putInt kicks in before getInt could modify the index, then there will be
race condition.
Is that correct? |
|
N********g 发帖数: 132 | 3 3. there are different kind of databases; given a query, system will tell
you which database you should connect(system gives you a string like "Oracle
" or "MySQL"). Design a class that could handle any query.
这题考的是separation of interface and implementation,code against interface
,not against implementation,如果做过JDBC开发,立马就知道什么意思。
好比你写了一些DAO(Database access object),就是用来把数据从数据库里面读出
来,然后交给中间层处理的工具类,但是你们开发组在不久的将来,打算把数据库由
oracle转成mysql。如果这些DAO里面的具体选取数据的方法,都跟oracle数据库相关,
都跟oralce对应的java class相关,那转数据库的时... 阅读全帖 |
|
N********g 发帖数: 132 | 4 3. there are different kind of databases; given a query, system will tell
you which database you should connect(system gives you a string like "Oracle
" or "MySQL"). Design a class that could handle any query.
这题考的是separation of interface and implementation,code against interface
,not against implementation,如果做过JDBC开发,立马就知道什么意思。
好比你写了一些DAO(Database access object),就是用来把数据从数据库里面读出
来,然后交给中间层处理的工具类,但是你们开发组在不久的将来,打算把数据库由
oracle转成mysql。如果这些DAO里面的具体选取数据的方法,都跟oracle数据库相关,
都跟oralce对应的java class相关,那转数据库的时... 阅读全帖 |
|
k**********i 发帖数: 177 | 5 list::iterator it;
it =tt.begin();
for (int i=0 ;i
{
for (int c = 0 ;c
{
if (data[1].at(c) =="int")
{
data[i+2][c] = it->getInt(v);
v++;
}
if (data[1].at(c) =="string")
{
data[i+2][ |
|
l******e 发帖数: 27 | 6 rs.updateInt(2, 1010);
rs.updateRow();
System.out.println(rs.getInt(new_att_index)); // print out the new value 1010
After rs is closed. The record in the databased is not changed! I'm using
ACCESS. |
|
m**i 发帖数: 89 | 7
If you want to identify if a field is null, don't use getInt(),
getShort(). |
|
G*********a 发帖数: 1080 | 8 it's really wired, i have a file of strings, and has methods such as
getString(int), getInt(String)... it worked fine before but today it keeps
throwing this error: java.io.EOFException
at java.io.RandomAccessFile.readInt(RandomAccessFile.java:705)
i didn't change any code of that part, and the file could be read into and
printout well, all the other String works fine, except. one is "persian"...
anyone knows the possible reason?
Thanks! |
|
d*r 发帖数: 238 | 9
Here is my program:
public class Test {
public Test() {
String sql =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testdb";
DriverManager.registerDriver(new SQLServerDriver());
Connection conn = DriverManager.createConnection(sql, "sa", "sa");
Statement stmt = conn.createStatement();
String query = "SELECT * FROM mytable";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
int i = rs.getInt("id");
|
|
B******N 发帖数: 445 | 10 first:pay attention that rs.getInt(column_number), the column_number is one
based not zero based.
second:
replace:
DriverManager.registerDriver(new SQLServerDriver());
Connection conn = DriverManager.createConnection(sql, "sa", "sa");
with this:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(sql, "sa", "sa"); |
|
c*y 发帖数: 137 | 11 In Java, methods are "virtual" by default. Only private, static or final
methods are not virtual. You don't need to put "virtual" when declaring a
method.
You can compile the sample code I gave you and see for yourself.
"overidding".
resolved
Java,
using
variables
the
getInt()
binding. |
|
t*****s 发帖数: 124 | 12 如果是jdbc 3.0,可以支持检索自动产生的key
ResultSet rs = stmt.getGeneratedKeys()
if (rs.netx())
{
int key = rs.getInt();
} |
|
b*****o 发帖数: 284 | 13 Use a package called "DataFile"
The following is a sample
// Creating a reader for CSV file using ISO-8859-1
DataFile read = DataFile.createReader("8859_1");
read.setDataFormat(new CSVFormat());
try {
read.open(new File("/data/test.csv"));
for (DataRow row = read.next(); row != null; row = read.next()) {
String text = row.getString(0);
int number1 = row.getInt(1, 0);
double number2 = row.getDouble(2);
// use the retrieved data ...
}
}
finally { |
|
m******t 发帖数: 2416 | 14 Whatever thread(s) stuck in putInt won't be able to proceed right away. They
would have to wait until the notifier thread exits getInt and releases the
lock. |
|
j****g 发帖数: 597 | 15 今天看programer_interview看到一个producer-customer并行的问题,用java写的(第7
章section 7.12). Program is written as:
class producer extends Thread {
......
void run() {
while (true) {
try {
putInt();
}
catch (...){};
}
}
private synchronized void putInt() throws ... {
while (index == MAX_CAPACITY) {
wait()
}
buffer[index] = ...
index++;
notifyAll();
}
private synchronized int getInt() throws ... {
notifyAll(); // I ha |
|
|
j****g 发帖数: 597 | 17 getInt的wait好像应该由putInt的notifyAll来释放吧? |
|
m******t 发帖数: 2416 | 18
releasing
be
There won't be.
The putInt thread, after waking up, would have to get hold of the lock
before it can actually resume execution. The getInt thread does _not_
relinguish its ownership on the lock just by calling notifyAll(). |
|
j****g 发帖数: 597 | 19 So does that mean "synchronized" keyword is actually putting lock on the
producer ocject itself but not the method. You can only enter EITHER putInt
OR getInt but you can't enter both from different threads.
right? |
|
z*******3 发帖数: 13709 | 20 另外关于直接变量的修改
这个你没有办法利用上接口
接口不定义变量,只定义方法
这样可以剥离耦合
比如a.int = b.int
那么这个时候你要连同B一起编译
而这个B只能是具体的实现类
这样耦合度明显增加
A和B的实现就很难拆开给两个人去写
因为A的编译需要用到B类,否则无法编译
而如果B是一个接口
那么a.int = b.getInt();
的话,A的编译只需要拿到B的接口就行了
B的实现跟A的实现分离
这也是最基本的分工的要求
否则你写的代码要等隔壁阿三写好才能编译
那就痛苦了 |
|