|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 17 2014 06:08 Nesserev wrote:Show nested quote +On May 17 2014 04:18 3FFA wrote:Thank you so much Ben and Nesserev! Especially for explaining it to me so that now I understand the why behind all of this.  Well, just to be sure, post your 'fixed' code, so that we're sure that you understand everything completely 
Here it is! A bit late, but I'll link to it in the post before yours. 
String songTitle = "Pompeii"; if(music.getDownloadInfo(songTitle) == null) System.out.println(songTitle + " was never downloaded"); else System.out.println(songTitle + " was downloaded " + music.getDownloadInfo(songTitle).getTimesDownloaded() + " times"); songTitle = "Jingle Bells"; if(music.getDownloadInfo(songTitle) == null) System.out.println(songTitle + " was never downloaded"); else System.out.println(songTitle + " was downloaded " + music.getDownloadInfo(songTitle).getTimesDownloaded() + " times");
|
|
|
+ Show Spoiler +import java.util.concurrent.*;
public class ThreadTest2 { private static final int FINISH = 2000000; private static int maxDivisorCount; private static int numberWithMaxDivsisors; private static ArrayBlockingQueue<DivisorTask> blockingQueue; /** * Gets the number of threads from the user and counts primes using that many threads. */ public static void main(String[] args) { int processors = Runtime.getRuntime().availableProcessors(); if (processors == 1) System.out.println("Your computer has only 1 available processor.\n"); else System.out.println("Your computer has " + processors + " available processors.\n"); int numberOfThreads = 0; while (numberOfThreads < 1 || numberOfThreads > 1000) { System.out.print("How many threads do you want to use (from 1 to 1000) ? "); //numberOfThreads = TextIO.getlnInt(); numberOfThreads = 8; if (numberOfThreads < 1 || numberOfThreads > 1000) System.out.println("Please enter 1, 2, 3, 4, 5, 6, 7, or 8 !"); } countDivisorsWithThreads(numberOfThreads); } private static void countDivisorsWithThreads(int numberOfThreads) { blockingQueue = new ArrayBlockingQueue<DivisorTask>(10000); int numTasks = 100; int increment = FINISH/numTasks; System.out.println("\nCounting primes between 1 and " + (FINISH) + " using " + numberOfThreads + " threads...\n"); long startTime = System.currentTimeMillis(); CountDivisorsThread[] worker = new CountDivisorsThread[numberOfThreads]; for (int i = 0; i < numberOfThreads; i++) worker[i] = new CountDivisorsThread(); numberWithMaxDivsisors = 0; maxDivisorCount = 0; for (int i = 0; i < numTasks; i++) try { blockingQueue.put(new DivisorTask(i * increment + 1, (i+1) * increment)); } catch (InterruptedException e) { } for (int i = 0; i < numberOfThreads; i++) worker[i].start(); for (int i = 0; i < numberOfThreads; i++) { while (worker[i].isAlive()) { try { worker[i].join(); } catch (InterruptedException e) { } } } if (blockingQueue.isEmpty()) worker = null; long elapsedTime = System.currentTimeMillis() - startTime; System.out.println("\nThe number with most divisors is " + numberWithMaxDivsisors + "."); System.out.println("\nThe number of divisors is " + maxDivisorCount + "."); System.out.println("\nTotal elapsed time: " + (elapsedTime/1000.0) + " seconds.\n"); } private static class CountDivisorsThread extends Thread { public CountDivisorsThread() { } public void run() { DivisorTask task = null; // try { // task = blockingQueue.take(); // } // catch (InterruptedException e) { // // } // while (!blockingQueue.isEmpty()) { // task.run(); // try { // task = blockingQueue.take(); // } // catch (InterruptedException e) { // // } // } while (!blockingQueue.isEmpty()) { try { task = blockingQueue.take(); } catch (InterruptedException e) { } task.run(); } } } private static class DivisorTask { int numDivisorsThread; int numWithMostThread; int min, max; public DivisorTask(int min, int max) { this.min = min; this.max = max; numDivisorsThread = 0; numWithMostThread = 0; } public void run() { int currentNum; int currentDivisor; for (int i = min; i < max + 1; i++) { currentNum = i; currentDivisor = countDivisors(i); if (currentDivisor > numDivisorsThread) { numWithMostThread = currentNum; numDivisorsThread = currentDivisor; } } System.out.println("The DIVnumber between " + min + " and " + max + " is " + numWithMostThread + "\n" + "The number of divisors that it has is " + numDivisorsThread + "\n" + "Is the task queue empty?: " + blockingQueue.isEmpty()); if (numDivisorsThread > maxDivisorCount) { newMax(numDivisorsThread, numWithMostThread); } } } private static int countDivisors(int num) { int count = 0; for (int i = 1; i < Math.sqrt(num); i++) { if (num % i == 0) count += 2; } if (Math.sqrt(num) - (int)Math.sqrt(num) == 0) count++; return count; } synchronized private static void newMax(int divisors, int number) { maxDivisorCount = divisors; numberWithMaxDivsisors = number; } }
In the CountDivisorsThread, there are two sections. The commented out section, and the current working section. When I run the commented out section, 7 thread finish, but the final thread/task does not complete and the program stops. As it currently stands, the program finishes. Why does the commented out section not complete the program? And why does it not complete the program with 7 threads finishing and the last one not finish? Even if I use setDaemon(true) in the constructor when I initialize the thread, the program still will not finish when I use the commented out section.
|
|
|
Ok. That makes sense why the final task doesn't run.
But when the thread sees that the queue is empty, shouldn't the thread end (since the run() method completes), which causes the thread to die, and thereby cause the program to complete (since worker[lastRemaining].join() should see that the thread died) and output the final strings. The program continues to run without outputting anything.
|
I'm working on this project that lets users manipulate a database from various windows forms. Every table in the database has an associated class with functions that call the necessary stored procedures and pass them the required values.
Most of these functions are written like so:
Public Shared Function AddNew(ByVal pCustomerID As Integer, ByVal pRecordType As String, ByVal pCustomerName As String, ByVal pBillingAddressID As Integer, ByVal pShippingAddressID As Integer, ByVal pPaymentTermsID As Integer, ByVal pShippingTermsID As String) As Boolean
<snip>
sqlinsertCommand.Parameters.AddWithValue("@CustomerID", pCustomerID) sqlinsertCommand.Parameters.AddWithValue("@RecordType", pRecordType) sqlinsertCommand.Parameters.AddWithValue("@CustomerName", pCustomerName) sqlinsertCommand.Parameters.AddWithValue("@BillingAddressID", pBillingAddressID) sqlinsertCommand.Parameters.AddWithValue("@ShippingAddressID", pShippingAddressID) sqlinsertCommand.Parameters.AddWithValue("@PaymentTermsID", pPaymentTermsID) sqlinsertCommand.Parameters.AddWithValue("@ShippingTermsID", pShippingTermsID)
<snip>
You call the function and you pass it the values it's looking for in the correct order and it uses those to set the stored procedure's parameters. easy
Then I ran into this function in another class which is supposed to serve the same purpose:
Public Shared Function AddNewPackage(ByVal ParamArray params() As Object) As Boolean
<snip>
For Each parameter In params oleinsertCommand.Parameters.AddWithValue("@" + parameter.Key, parameter.Value) Next
<snip>
This requires creating an object with a separate key for each value I want to pass to the stored procedure. Additionally, the function will accept any number of arguments even though the stored procedure it calls requires exactly 26 parameters. Why would anyone do it that way?
|
How does one make enterprise android app development not suck? Has anyone found a nice alternative to native when interacting heavily with a backend rest service? Is using appcelerator worth it just for the mvc architecture? Any other ideas to deal with the asynchronous nature of android combined with calling http continuously?
|
Depends on where you think your bottleneck is, the phone download speed or your backend rest service? Need a little bit more data.
In general good apps just break things down well enough and have good enough UI that the user just doesn't feel like there's a problem getting data. Like if you're downloading 50 times at once, paginate more and better, and handle cancellation better.
|
On May 20 2014 13:21 Blisse wrote: Depends on where you think your bottleneck is, the phone download speed or your backend rest service? Need a little bit more data.
In general good apps just break things down well enough and have good enough UI that the user just doesn't feel like there's a problem getting data. Like if you're downloading 50 times at once, paginate more and better, and handle cancellation better.
It's not a performance thing its a code cleanliness thing. Using async tasks is dangerous because one can't rely on the current UI state when the async task finishes, so if you get the timing wrong the app just crashes. Using asynctaskloaders is a lot of boilerplate on every request. You could try to break everything out into services or use Dobjanschi's style of architecture, but that just feels so overly complicated.
Sorry for the lack of info, it was a half bitch / half throwing something out there and hoping for a miracle. We've picked up android dev for our warehouse and it just feels so overly complex. I've been working with web flows for quite a while now, and it's just not the easiest of transitions. It's not that you can't make it work, you just have to deal with so many considerations because android can kill your stuff when it gets backgrounded or you how you aren't supposed to make http requests from the ui thread.
|
Hello everyone! I've got a question for you all. Sorry if it has already been answered, I looked through the OP and didn't find anything like it.
First my background: I've almost finished my computer science school and I can code efficiently in C, C++ and Java. Of these 3 I prefer C++.
Now I have a project a developping a RPG video game with some friends. I looked on the web for either some engine or some framework that would help me do that. The one I saw the most was Unity, but it seemed that it seems to use a very high level language, which is not very funny! (=
This game I want to develop would be in 2D, soloplayer, for PC (mouse / keyboard) and turn base, so not a lot of efficiency is actually needed.
My question would be: Would you have any advice on what framework or engine I could / should use for my game?
Thanks in advance for any advice you could give me!
|
|
|
On May 20 2014 21:39 nunez wrote:maybe sdl?
Seems pretty nice! Low level, works natively with C++, I like that. I'll give it a try!
|
|
|
On May 20 2014 05:27 Mindcrime wrote: I'm working on this project that lets users manipulate a database from various windows forms. Every table in the database has an associated class with functions that call the necessary stored procedures and pass them the required values.
Most of these functions are written like so: *snip*
You call the function and you pass it the values it's looking for in the correct order and it uses those to set the stored procedure's parameters. easy
Then I ran into this function in another class which is supposed to serve the same purpose: *snip*
This requires creating an object with a separate key for each value I want to pass to the stored procedure. Additionally, the function will accept any number of arguments even though the stored procedure it calls requires exactly 26 parameters. Why would anyone do it that way? Programmers trying to be too clever or too lazy. This is just something waiting to go wrong.
|
On May 20 2014 23:37 Nesserev wrote:To be honest, SDL seems to be a bit overkill for his project. SFML seems like the right tool for the job, everything you need to make a 2D game. Also, there's a 'game development' book for SFML that introduces you to some aspects of game programming, like resourceholders, adding shaders, etc. : book (You can also find it on TPB).
Thanks! I'll give it a look.
|
On May 20 2014 19:04 berated- wrote:Show nested quote +On May 20 2014 13:21 Blisse wrote: Depends on where you think your bottleneck is, the phone download speed or your backend rest service? Need a little bit more data.
In general good apps just break things down well enough and have good enough UI that the user just doesn't feel like there's a problem getting data. Like if you're downloading 50 times at once, paginate more and better, and handle cancellation better. It's not a performance thing its a code cleanliness thing. Using async tasks is dangerous because one can't rely on the current UI state when the async task finishes, so if you get the timing wrong the app just crashes. Using asynctaskloaders is a lot of boilerplate on every request. You could try to break everything out into services or use Dobjanschi's style of architecture, but that just feels so overly complicated. Sorry for the lack of info, it was a half bitch / half throwing something out there and hoping for a miracle. We've picked up android dev for our warehouse and it just feels so overly complex. I've been working with web flows for quite a while now, and it's just not the easiest of transitions. It's not that you can't make it work, you just have to deal with so many considerations because android can kill your stuff when it gets backgrounded or you how you aren't supposed to make http requests from the ui thread. A service isn't complicated at all. I use IntentService for all my HTTP operations. There is also a custom class called WakefulIntentService: https://gitorious.org/kolab-android/kolab-android/source/5ed8bcb214249fd955962ccfa282524cd19e8b44:src/com/commonsware/cwac/wakeful/WakefulIntentService.java
|
On May 20 2014 19:04 berated- wrote:Show nested quote +On May 20 2014 13:21 Blisse wrote: Depends on where you think your bottleneck is, the phone download speed or your backend rest service? Need a little bit more data.
In general good apps just break things down well enough and have good enough UI that the user just doesn't feel like there's a problem getting data. Like if you're downloading 50 times at once, paginate more and better, and handle cancellation better. It's not a performance thing its a code cleanliness thing. Using async tasks is dangerous because one can't rely on the current UI state when the async task finishes, so if you get the timing wrong the app just crashes. Using asynctaskloaders is a lot of boilerplate on every request. You could try to break everything out into services or use Dobjanschi's style of architecture, but that just feels so overly complicated. Sorry for the lack of info, it was a half bitch / half throwing something out there and hoping for a miracle. We've picked up android dev for our warehouse and it just feels so overly complex. I've been working with web flows for quite a while now, and it's just not the easiest of transitions. It's not that you can't make it work, you just have to deal with so many considerations because android can kill your stuff when it gets backgrounded or you how you aren't supposed to make http requests from the ui thread.
Ohhh, code cleanliness LOL sorry misinterpreted that.
|
Does anyone know about agent oriented programming? What do you think of it? My lectures suggest that it can be done in an OOP language but that's kind of meh. The agent notion has some cool concepts but they seem more like theory rather than possible.
|
Agents are far from theory, look at ericson / erlang and how that runs half of the worlds telecommunication switches, agents are an awesome tool when you need a highly distributed environment and using traditional locks & synchronization just doesn't cut it anymore. I've worked on a distributed application in erlang and also in scala using akka and can't imagine how we could have done it without actors.
|
In java, I cannot seem to create a generic array.
Task<T>[] t = new Task<T>[2];
however, a generic arraylist works;
ArrayList<Task<T>> t = new ArrayList<Task<T>>();
I'm not sure why as a Task<T> is just an object, and Object[] is usually a valid array declaration and Object[i] is usually a valid array of size i.
|
|
|
|
|
|