|
Nagy Vilmos wrote: Clever! Who would of thought to search Google...
Fewer than 10% of new posters here
|
|
|
|
|
Richard MacCutchan wrote: Fewer than 10% of new posters here
ftfy
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
public class RunThread
{
public static void main(String[] args) throws InterruptedException
{
TwoThread tt = new TwoThread();
tt.start();
for(int i = 0;i<25;i++)
{
System.out.println("Main Thread");
}
}
}
class TwoThread extends Thread
{
public void run()
{
for(int i=0;i<25;i++)
System.out.println("New Thread");
}
}
The output of this program is always "Main Thread" displayed 25 times followed by "New Thread" 25 times. Can someone explain why this sequence is always followed? Even though a thread is already spawned, why does the main function always get executed before the new thread?
|
|
|
|
|
Since you included run in your second thread then you need to invoke that method not start so you have to change the tt.start() to tt.run()
|
|
|
|
|
When several threads are ready (i.e. not waiting on something), the Windows kernel will select one thread (actually one thread for each available core) and run it; it relies on process priority, thread priorities and historic information to decide which one(s). And it will typically reconsider only at specific points in time (some 60 times per second). As soon as a thread becomes ready or a running thread is no longer ready (e.g. it blocks on a WaitOne), it will reconsider.
Your code not having any thread synchronization leaves full freedom to the kernel, which applies a specific algorithm, so don't expect random behavior for short-lived threads.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
Be forewarned: this is a difficult question; folks on StackOverflow, Eclipse forums, Sun forums, and ComEclipse support, and others have been stumped by it. If you can answer this, you're a certified programming god.
---
How can I create an SWT Variant object that contains a float array?
Since SWT's Variant type doesn't support this out of the box, here's my attempt to make this work:
public static Variant CreateVariantForArray(float[] array)
{
if(array == null){
return null;
}
short FADF_FIXEDSIZE = 0x10;
short FADF_HAVEVARTYPE = 0x80;
short fFeatures = (short) (FADF_FIXEDSIZE | FADF_HAVEVARTYPE);
int elementSize = 4;
int pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
4 * array.length);
OS.MoveMemory(pvData, array, 4 * array.length);
int sizeofSafeArray = 12 + 4 + 1 * 8;
int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
sizeofSafeArray);
int offset = 0;
OS.MoveMemory(pSafeArray + offset, new short[] { 1 }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new short[] { fFeatures }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new int[] { elementSize }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { pvData }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { array.length }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4);
offset += 4;
int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);
short vt = (short) (OLE.VT_ARRAY | OLE.VT_R4);
OS.MoveMemory(pVariant, new short[] { vt }, 2);
OS.MoveMemory(pVariant + 8, new int[] { pSafeArray }, 4);
return new Variant(pVariant, OLE.VT_VARIANT);
}
It doesn't work. Any idea why? Or better yet, got any code that takes a float[] and gives back a Variant?
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Here is a thought, What is an array? an array is a collection of elements. The array has size right, then why not use a for loop with that size and loop over the float array and pass the value in each iteration to the method that does the manipulation .
|
|
|
|
|
You're suggesting something like
float[] myFloats = new float[] { 4.2, 7.5 };
for (int i = 0; i<myFloats.length; i++)
{
automation.Invoke(bazMethodId, myFloats[i]);
}
That doesn't work, I'm afraid. The 3rd party COM object expects an array, not a float. Passing in a float results in an exception.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Whats the name of the COM product?
|
|
|
|
|
I'm not at liberty to say, actually. It's a legacy COM object from the 1990s. It is no longer being supported by its authors, but we cannot yet migrate away from it.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
What does the COM understand (i mean an array of type?) and on the receiving side what are you guys doing?
|
|
|
|
|
Using the OleView COM object viewer tool in the Windows SDK, the COM Interface Definition Language (IDL) code looks like this:
void Baz([in]VARIANT floatArray);
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
|
Yeah, I've investigated how the .NET framework marshals this. It helped a little, but still didn't solve my problem. Thanks anyways.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
i'm developing a simple code to test branch coverage.
where can i found the source code?
and where can i found some of the Java class which relate to my project?
|
|
|
|
|
Shakirin Mohd Amin wrote: i'm developing a simple code to test branch coverage.
Simple is always good.
Shakirin Mohd Amin wrote: where can i found the source code?
You are developing it so only you can answer this question.
Shakirin Mohd Amin wrote: and where can i found some of the Java class which relate to my project?
Where did you last see it?
|
|
|
|
|
no. i mean where i can find some example of code or pseudo code for coverage tool.
im just a student. im still learning about it. so i dont have so much knowledge about it. hope that you all can help me
|
|
|
|
|
Shakirin Mohd Amin wrote: where i can find some example of code or pseudo code for coverage tool.
I don't know what a coverage tool is, but if you search Google you should find some examples.
|
|
|
|
|
i've been searching for almost 1 month. but yet still didnt found any of that either sample source code or pseudo code ;(
|
|
|
|
|
What about these[^], first hits on Google; took me 5 seconds.
|
|
|
|
|
If you google for it you will find lots of information.
The two that I have heard mentioned most in connection with Java are Clover and Cobertura. There is also an open-source Java code coverage tool called Emma.
|
|
|
|
|
|
i've tried to look at those tolls before. but i doesnt give me any source code or guide to develop my own tool
|
|
|
|
|
yes, i found about clover & corbetura. but my problem now is how am i going to develop the code.
i know the flow of it. but i still don't know how to write the code.
|
|
|
|
|
Thats why they are called Open source you can get the source code of any program given the license supports it for example,
Look for the file with src[^]
|
|
|
|